Putting it all together
We already extracted the entities and recognized the intent in several ways. We're now ready to put it all together to calculate a semantic representation for a user utterance!
- We'll process the example dataset utterance:
show me flights from denver to philadelphia on tuesday
We'll hold a dictionary object to hold the result. The result will include the entities and the intent.
- Let's extract the entities:
import spacy from spacy.matcher import Matcher nlp = spacy.load("en_core_web_md") matcher = Matcher(nlp.vocab) pattern = [{"POS": "ADP"}, {"ENT_TYPE": "GPE"}] matcher.add("prepositionLocation", [pattern]) # Location entities doc = nlp("show me flights from denver to philadelphia on tuesday") matches = matcher(doc) for mid, start, end in matches: print(doc[start:end]) ... from denver to philadelphia # All entities: ents = doc...