示例#1
0
 def testGetPoSTags(self):
     s = Sentence(TEST_TOKENS)
     s.addAnnotation('mask', 2, 4)
     s.addAnnotation('mask', 6)
     self.assertListEqual(list(s.posTags(3, 7)), [
         'pos3', 'pos4', 'pos5', 'pos6'
     ])
示例#2
0
文件: textclass.py 项目: fnl/libfnl
def asDict(sentence: Sentence, ngrams=2):
    """Convert a :class:`fnl.text.sentence.Sentence` into a feature dictionary."""
    d = {'gene-count': sentence.countEntity('B-gene')}
    stems = list(sentence.maskedStems())
    pos = sentence.posTags()
    tokens = Counter('{}/{}'.format(s, t) for s, t in zip(stems, pos))
    d.update(tokens)

    if "TARGET/NN" in d and "FACTOR/NN" in d:
        d['has-all-entities'] = 1

    gram = list(stems)

    while ngrams > 1:
        ngrams =- 1
        tokens = Counter('{} {}'.format(s, g) for s, g in zip(stems, gram[1:]))
        d.update(tokens)

    return d
示例#3
0
def asDict(sentence: Sentence, ngrams=2):
    """Convert a :class:`fnl.text.sentence.Sentence` into a feature dictionary."""
    d = {'gene-count': sentence.countEntity('B-gene')}
    stems = list(sentence.maskedStems())
    pos = sentence.posTags()
    tokens = Counter('{}/{}'.format(s, t) for s, t in zip(stems, pos))
    d.update(tokens)

    if "TARGET/NN" in d and "FACTOR/NN" in d:
        d['has-all-entities'] = 1

    gram = list(stems)

    while ngrams > 1:
        ngrams = -1
        tokens = Counter('{} {}'.format(s, g) for s, g in zip(stems, gram[1:]))
        d.update(tokens)

    return d
示例#4
0
 def testGetPoSTags(self):
     s = Sentence(TEST_TOKENS)
     s.addAnnotation('mask', 2, 4)
     s.addAnnotation('mask', 6)
     self.assertListEqual(list(s.posTags(3, 7)),
                          ['pos3', 'pos4', 'pos5', 'pos6'])