class TestObjectTerm(unittest.TestCase): def setUp(self): self.ot = ObjectTerm(text='医師の診断', context='治療') def test_set_core_noun_from_name(self): self.ot.set_core_noun_from_name() self.assertEqual(self.ot.core_noun, '診断')
def _obj_and_predicate_dict_by_wo_from_sentences(self): """ self.sentencesから、「〜〜を〜〜」を見つけて、「AをB」にして返す 最後に計算する際、同じページでの登場番号の前後で。part-ofを判断する """ results = [] order = 0 self._set_subtypes() for i, sentence in enumerate(self.sentences): if type(sentence) == str: sentence = Sentence(text=sentence, query=self.query) if not sentence.set_noun_verb_if_good_task(): continue object_term = ObjectTerm(sentence.noun) if object_term == 'ましょ': pdb.set_trace() if object_term.core_noun in constants.STOPWORDS_OF_WEBPAGE_NOUN: continue distance_between_subtypes = {} for subtype in self.subtypes: distance = self._distance_between_subtype(i, subtype=subtype) distance_between_subtypes[subtype] = distance task = Task(object_term=object_term.name, cmp=sentence.cmp, predicate_term=sentence.verb, distance_between_subtypes=distance_between_subtypes, query=self.query, order=order, url=self.url, is_shopping=False, is_official=False, rank=self.rank, sentence=sentence.body) results.append(task) print('%s_%s_%sというタスクをセットしました' % (sentence.noun, sentence.cmp, sentence.verb)) order += 1 # 登場の順番 return results
def __init__(self, distance_between_subtypes, object_term, cmp='を', predicate_term='', query='', order=0, url='', is_shopping=False, is_official=False, rank=1000, sentence=''): object_term_obj = ObjectTerm(text=object_term, query=query) self.object_term = object_term_obj self.predicate_term = predicate_term self.distance_between_subtypes = distance_between_subtypes # {'シャワールーム': -3, ...} self.query = query self.cmp = cmp self.order = order self.url = url self.is_shopping = is_shopping self.is_official = is_official self.rank = rank self.sentence = sentence
def setUp(self): self.ot = ObjectTerm(text='医師の診断', context='治療')