Example #1
0
def load_negation(version=None, path=None, skip=False, variation=0):
    if skip:
        return None
    elif path:  # requirement: must precede version as sometimes 'path' is always specified
        return StatusMiner(path=path, rx_var=variation)
    elif version:
        return StatusMiner(tablename=f'status{version}', rx_var=variation)
    else:
        raise ValueError('No negation cues provided!')
Example #2
0
def test_negation_bidirectional():
    miner = StatusMiner(rules=[])
    terms = [
        Term('I', 0, 1, 'C01', 1),
        Word('have', 2, 6),
        Negation('no', 7, 9, 'negn', 3),
        Term('beer', 10, 14, 'C02', 2),
    ]
    miner.postprocess(terms)
    assert terms[0].is_negated()
    assert terms[-1].is_negated()
Example #3
0
def test_negation_end_scope_conj():
    miner = StatusMiner(rules=[])
    terms = [
        Term('I', 0, 1, 'C01', 1),
        Word('have', 2, 6),
        Negation('no', 7, 9, 'negn', 3),
        Term('beer', 10, 14, 'C02', 2),
        Negation('or', 15, 17, 'conj', 0),
        Term('wine', 18, 22, 'C02', 3),
    ]
    miner.postprocess(terms)
    assert terms[0].is_negated()
    assert terms[-3].is_negated()  # negates 'beer'
    assert not terms[-1].is_negated()  # 'or' blocks 'wine' from being negated
Example #4
0
def test_hypothetical_sentence(concept_file):
    mc = MinerCollection()
    mc.add(ConceptMiner([CsvDictionary(concept_file)]))
    mc.add(StatusMiner())
    concepts, sentence = mc.parse_sentence('if there is bad weather', offset=0)
    for concept in concepts:
        assert concept.is_hypothetical()
Example #5
0
def test_negated_sentence(concept_file):
    mc = MinerCollection()
    mc.add(ConceptMiner([CsvDictionary(concept_file)]))
    mc.add(StatusMiner())
    concepts, sentence = mc.parse_sentence('no bad weather', offset=0)
    for concept in concepts:
        assert concept.is_negated()
Example #6
0
def prepare(documents: List[Document], dictionaries: List[Dictionary],
            outputs: List[Output], negation_dicts: List[Dictionary]):
    """
    :param documents:
    :param dictionaries:
    :param outputs:
    :param negation_dicts:
    """
    mc = MinerCollection(ssplit=SentenceBoundary().ssplit)
    mc.add(ConceptMiner(dictionaries))
    mc.add(StatusMiner(negation_dicts))

    for out in outputs:
        out.create_output()

    logging.info('Retrieving notes.')
    for document in documents:
        for num, doc in enumerate(document.read_next()):
            if num % 100 == 0:
                logging.info(f'Completed: {num:>5}.')

            for sent_no, (sentence, cleaned_text) in enumerate(mc.parse(doc)):
                for feat, new in sentence:
                    for out in outputs:
                        out.writerow(doc.get_metalist(),
                                     feat,
                                     text=doc.get_text())
    logging.info('Completed: 100%')
Example #7
0
def test_negation_with_punct3():
    miner = StatusMiner(rules=[(r'c\s*/\s*o', 'negn', 3)])
    assert len(miner.mine('pt c/o', 0)) == 1
    assert len(miner.mine('pt c / o', 0)) == 1
Example #8
0
def test_negation_with_punct2():
    miner = StatusMiner(rules=[('c / o', 'negn', 3)])
    assert len(miner.mine('pt c/o', 0)) == 0
    assert len(miner.mine('pt c / o', 0)) == 1
Example #9
0
def test_statusminer_hypothetical():
    s = StatusMiner()
    negations = s.mine('if he wants to', 0)
    assert len(negations) == 1
Example #10
0
def test_statusminer_negated():
    s = StatusMiner()
    negations = s.mine('no evidence of anything', 0)
    assert len(negations) == 1