Created
February 6, 2019 05:30
-
-
Save mohdsanadzakirizvi/566641bf2823488857cd1a3506b90ae4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# get the named entity tag | |
print('---') | |
print('named entity tag of token') | |
print(token.ner) | |
# get an entity mention from the first sentence | |
print('---') | |
print('first entity mention in sentence') | |
print(sentence.mentions[0]) | |
# access the coref chain | |
print('---') | |
print('coref chains for the example') | |
print(ann.corefChain) | |
# Use tokensregex patterns to find who wrote a sentence. | |
pattern = '([ner: PERSON]+) /wrote/ /an?/ []{0,3} /sentence|article/' | |
matches = client.tokensregex(text, pattern) | |
# sentences contains a list with matches for each sentence. | |
assert len(matches["sentences"]) == 3 | |
# length tells you whether or not there are any matches in this | |
assert matches["sentences"][1]["length"] == 1 | |
# You can access matches like most regex groups. | |
matches["sentences"][1]["0"]["text"] == "Chris wrote a simple sentence" | |
matches["sentences"][1]["0"]["1"]["text"] == "Chris" | |
# Use semgrex patterns to directly find who wrote what. | |
pattern = '{word:wrote} >nsubj {}=subject >dobj {}=object' | |
matches = client.semgrex(text, pattern) | |
# sentences contains a list with matches for each sentence. | |
assert len(matches["sentences"]) == 3 | |
# length tells you whether or not there are any matches in this | |
assert matches["sentences"][1]["length"] == 1 | |
# You can access matches like most regex groups. | |
matches["sentences"][1]["0"]["text"] == "wrote" | |
matches["sentences"][1]["0"]["$subject"]["text"] == "Chris" | |
matches["sentences"][1]["0"]["$object"]["text"] == "sentence" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment