Last active
December 27, 2015 11:49
-
-
Save language-engineering/7321434 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
# Say for example we acquire a list of BasicToken objects by getting all the dependants of a token: | |
dependants = parsed_sentence.get_dependants(aspect_token) | |
# We could filter that list, keeping only those tokens whose dependency relations with the aspect token are "dobj", by doing the following: | |
dependants = [token for token in dependants if token.deprel == "dobj"] | |
# Or we could filter that list, keeping only those tokens whose PoS tags are "RB" (for adverb) | |
dependants = [token for token in dependants if token.pos == "RB"] | |
# Or we could filter that list, keeping only those tokens whose form is NOT "main" or "special" | |
dependants = [token for token in dependants if token.form != "main" and token.form != "special"] | |
# Or if we had a single token, we could choose to add it to a list or not based on its properties | |
opinions = [] | |
if token.pos.startswith("JJ"): # If token is an adjective, then append its form to our list of opinions | |
opinions.append(token.form) | |
# Or we could search tokens for a property we wish to know is present | |
found_det = False | |
for dependant in dependants: | |
if dependant.deprel == "det": | |
found_det = True | |
# Now subsequent code can use "found_det" to perform different tasks depending on | |
# whether or not there was a determiner relation in the dependants. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment