Question: Step 4: Find the hypernym and hyponyms on processed chunked results Define Hearst patterns. Besides the regex, we also need to specify whether the hypernym
Step 4: Find the hypernym and hyponyms on processed chunked results Define Hearst patterns. Besides the regex, we also need to specify whether the hypernym is in the first part or the second part in the pattern . For example, in the pattern NP1 such as NP2 AND NP3, the hypernym is the first part of the pattern in the pattern NP1 , NP2 and other NP3, the hypernym is the last part of the pattern. After regex matching, find all the NPs and extract the hypernym and hyponym pairs based on the first or last attribute. Clean the NPs by removing the prefix NP_ and In (8): # Given by the prepared text, return the hypernym-hyponym pairs def hyponym_extract (prepared_text, hearst_patterns): # your implementation return pairs hearst_patterns - ("(NP_\w+ ( )?such as (NP_\*+ ?())?(and for 37)+)", "first"), ("((NP_\W+ ?(,)?)+(and for other NP_\w+)","last")] # two examples for hearst pattern print (hyponym_extract (prepare_chunks(np_chunking("I like to listen to music from musical genres, such as blues, rock a print(hyponym_extract (prepare_chunks (np_chunking("He likes to play basketball, football and other sports.")), hearst_p ("NP_blue', 'NP_musical_genre'), ('NP_rock', 'NP_musical_genre'), ('NP_jazz', 'NP_musical_genre')] [('NP_basketbalt', 'NP_sport'), ('NP_football', 'NP_sport'] In (10): def find_hyponyms (sentence, hearst_patterns): # your implementation print(find_hyponyms (I like to listen to music from musical genres, such as blues, rock and jazz., hearst_pattern print(find_hyponyms (He likes to play basketball, football and other sports.", hearst_patterns)) ("NP_blue', 'NP_musical_genre'), ('NP_rock', 'NP_musical_genre'), ('NP_jazz', 'NP_musical_genre')) ILONP_basketball, 'NP_sport'), (NP_football, TNP_sport')11 In [11]: def clean_np(term): return term.replace("NP_", ").replace("","") clean_np( 'NP_football Out(11): "football Step 4: Find the hypernym and hyponyms on processed chunked results Define Hearst patterns. Besides the regex, we also need to specify whether the hypernym is in the first part or the second part in the pattern . For example, in the pattern NP1 such as NP2 AND NP3, the hypernym is the first part of the pattern in the pattern NP1 , NP2 and other NP3, the hypernym is the last part of the pattern. After regex matching, find all the NPs and extract the hypernym and hyponym pairs based on the first or last attribute. Clean the NPs by removing the prefix NP_ and In (8): # Given by the prepared text, return the hypernym-hyponym pairs def hyponym_extract (prepared_text, hearst_patterns): # your implementation return pairs hearst_patterns - ("(NP_\w+ ( )?such as (NP_\*+ ?())?(and for 37)+)", "first"), ("((NP_\W+ ?(,)?)+(and for other NP_\w+)","last")] # two examples for hearst pattern print (hyponym_extract (prepare_chunks(np_chunking("I like to listen to music from musical genres, such as blues, rock a print(hyponym_extract (prepare_chunks (np_chunking("He likes to play basketball, football and other sports.")), hearst_p ("NP_blue', 'NP_musical_genre'), ('NP_rock', 'NP_musical_genre'), ('NP_jazz', 'NP_musical_genre')] [('NP_basketbalt', 'NP_sport'), ('NP_football', 'NP_sport'] In (10): def find_hyponyms (sentence, hearst_patterns): # your implementation print(find_hyponyms (I like to listen to music from musical genres, such as blues, rock and jazz., hearst_pattern print(find_hyponyms (He likes to play basketball, football and other sports.", hearst_patterns)) ("NP_blue', 'NP_musical_genre'), ('NP_rock', 'NP_musical_genre'), ('NP_jazz', 'NP_musical_genre')) ILONP_basketball, 'NP_sport'), (NP_football, TNP_sport')11 In [11]: def clean_np(term): return term.replace("NP_", ").replace("","") clean_np( 'NP_football Out(11): "football
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
