FillTheBlanks / test2.py
ashishraics's picture
final basic app
1d43b95
import pke
import nltk
nltk.download('stopwords')
nltk.download('wordnet')
nltk.download('punkt')
from nltk.corpus import stopwords,wordnet
import string
def get_noun_adj_verb(text):
output = []
try:
# initialize keyphrase extraction model, MultipartiteRank is the most recent model
extractor = pke.unsupervised.MultipartiteRank()
extractor.load_document(input=text, language='en',normalization=None)
stoplist = list(string.punctuation)
stoplist += ['-lrb-', '-rrb-', '-lcb-', '-rcb-', '-lsb-', '-rsb-']
stoplist += stopwords.words('english')
# keyphrase candidate selection #'ADJ' 'ADP' 'ADV' 'AUX' 'DET' 'NOUN' 'NUM' 'PART' 'PROPN' 'PUNCT' 'VERB' e.g POS={'VERB}
extractor.candidate_selection(pos={'NOUN', 'PROPN', 'ADJ'})
# candidate weighting,
extractor.candidate_weighting(threshold=0.74,alpha=1.1,method='average')
keyphrases = extractor.get_n_best(n=5)
for val in keyphrases:
output.append(val[0])
except Exception as e:
return e
return output
default_paratext = """On May 4, the Red Planet was rocked by a roughly magnitude 5 temblor, the largest Marsquake detected to date, NASA’s Jet Propulsion Laboratory in Pasadena, Calif., reports. The shaking lasted for more than six hours and released more than 10 times the energy of the previous record-holding quake.The U.S. space agency’s InSight lander, which has been studying Mars’ deep interior since touching down on the planet in 2018 (SN: 11/26/18), recorded the event. The quake probably originated near the Cerberus Fossae region, which is more than 1,000 kilometers from the lander.Cerberus Fossae is known for its fractured surface and frequent rockfalls. It makes sense that the ground would be shifting there, says geophysicist Philippe Lognonné, principal investigator of the Seismic Experiment for Interior Structure, InSight’s seismometer. “It’s an ancient volcanic bulge.Just like earthquakes reveal information about our planet’s interior structure, Marsquakes can be used to probe what lies beneath Mars’ surface (SN: 7/22/21). And a lot can be learned from studying this whopper of a quake, says Lognonné, of the Institut de Physique du Globe de Paris. “The signal is so good, we’ll be able to work on the details."""
print(type(get_noun_adj_verb(default_paratext)))