I am trying to extract a phrase from textual data. I am currently using SpaCy Rule-Based Matching. This is working fine until I saw that "Hiv-1 dna quant", this phrase is not getting detected. The patter I used is shown in the below code.
matcher = Matcher(nlp.vocab)
pattern = [{'LOWER': 'hiv'}, {"IS_PUNCT": True}, {"TEXT": {"REGEX":"\d{1,2}"}},
{'LOWER': 'dna'},
{'LOWER': 'quant'}]
matcher.add("HelloWorld", [pattern])
data = "probe Hiv-1 dna amp probe Hiv-1 dna quant Hiv-2 dna dir probe Hiv-2 dna"
doc = nlp(data)
matches = matcher(doc)
for match_id, start, end in matches:
string_id = nlp.vocab.strings[match_id] # Get string representation
span = doc[start:end] # The matched span
print(span.text)
I have also tried the following pattern
pattern = [{"LOWER": "hiv"}, {"IS_PUNCT": True}, {"LOWER":"1"}, {"LOWER": "dna"}, {"LOWER":"quant"}]
But it doesnt detect it.
Is there any other way to do this?