forked from explosion/spacy-course
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexc_01_12_01.py
25 lines (20 loc) · 845 Bytes
/
exc_01_12_01.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import spacy
from spacy.matcher import Matcher
nlp = spacy.load("es_core_news_sm")
matcher = Matcher(nlp.vocab)
doc = nlp(
"Después de hacer la actualización de iOS no notarás un rediseño "
"radical del sistema: no se compara con los cambios estéticos que "
"tuvimos con el iOS 7. La mayoría de las funcionalidades del iOS 11 "
"siguen iguales en el iOS 10."
)
# Escribe un patrón para las versiones de iOS completas
# ("iOS 7", "iOS 11", "iOS 10")
pattern = [{"TEXT": ____}, {"IS_DIGIT": ____}]
# Añade el patrón al matcher y usa el matcher sobre el documento
matcher.add("IOS_VERSION_PATTERN", [pattern])
matches = matcher(doc)
print("Total matches found:", len(matches))
# Itera sobre los resultados e imprime el texto del span
for match_id, start, end in matches:
print("Match found:", doc[start:end].text)