Semantic Parsing With Nltk
Solution 1:
It seems like you want to identify imperatives.
This answer has looked into that and contains a solution similar to your option (a), but a bit different since it lets the tagger do most of the work. (b) indeed seems a bit hacky... but you're creating a pretty custom application, so it could work! I would do (c) the other way around - parsing and then chunking based on the CFG in (a).
Overall, however, as the other answer explains, there doesn't seem to be a perfect way to do this just yet.
You might also want to look at pattern.en (also see their GitHub repo). Their
mood()
function tries to identify a parsed Sentence as indicative, imperative, conditional or subjunctive
Solution 2:
For a related task (replication of a semantic parser of commercial transactions, I previously did something like (c). The biggest advantage of cascaded parser workflows is that the grammars can stay relatively simple (and fast), because they don't have to do global disambiguation. I guess it's the least hacky approach here because it's actually a valid strategy to design parser workflows.
As for (a), the custom tagger would require some kind of training data. If you can create or bootstrap that, that would be the most natural solution. For doing span annotations with a tagger, consider using the BIO (IOBES) schema as commonly used for named entity annotations, i.e., You/B-COMMAND shall/I-COMMAND not/I-COMMAND pass/E-COMMAND !/O
.
Solution 3:
I would suggest you use the "rule-based matcher" that is available in spacy, which provides options as Token Matcher, Phrase Matcher, Entity Ruler. I have used Token Matcher specifying the pattern (go + to + place), and it worked very well.
token_pattern = [{"LEMMA": "go"}, {"POS": "ADP"}, {"POS": "PROPN"}]
This pattern would find "go to New York" or "going to New York" or "went with Mary", etc.
Also, if you are only trying to extract nouns like in your example "San Francisco", "123 Main Street", NER (Named Entity Recognition) might help.
Post a Comment for "Semantic Parsing With Nltk"