def checkFirstSentence_test5(paragraphID, paragraph): if paragraphID in cache: tokens = cache[paragraphID] else: tokens = getParagraphTokenIntersectionByID(paragraphID) cache[paragraphID] = tokens for token in tokens: if token in paragraph[0]: return True for token in tokens: tokenSynset = getSynset(token, paragraphID) if tokenSynset: partOfSpeechMap = POSCache[paragraphID] tokenPos = partOfSpeechMap[token] for word in paragraph[0].split(" "): word = word.strip().lower() if word in partOfSpeechMap: wordPos = partOfSpeechMap[word] if wordPos == tokenPos: wordSynset = getSynset(word, paragraphID) if wordSynset: if ( wn.path_similarity(tokenSynset, wordSynset) and wn.path_similarity(tokenSynset, wordSynset) > 0.13 ): return True return False
def isValid(paragraphID, paragraph, aggressive): #must cache tokens if paragraphID in cache: tokens = cache[paragraphID] else: tokens = getParagraphTokenIntersectionByID(paragraphID) cache[paragraphID] = tokens if aggressive: counter = 0 for token in tokens: if token in paragraph: counter += 1 if counter >= len(tokens): return True else: for token in tokens: if token in paragraph: return True return False