Ejemplo n.º 1
0
def test_shortcuts_spacy_inline():
    spacy = pytest.importorskip("spacy", minversion="2.1")
    nlp = spacy.load("en_core_web_sm")
    rules = """
    {WORD("TEST")}->MARK("TEST")
    """
    setup_spacy(nlp, rules_string=rules)
Ejemplo n.º 2
0
def spacy_engine(rules, **kwargs):
    spacy = pytest.importorskip("spacy", minversion="2.1")
    nlp = spacy.load("en_core_web_sm")
    setup_spacy(nlp, rules_string=rules, override_ents=True, **kwargs)
    patterns = rita.compile_string(rules, **kwargs)
    print(patterns)

    def parse(text):
        doc = nlp(text)
        return list([(e.text, e.label_) for e in doc.ents])
    return parse
Ejemplo n.º 3
0
def test_shortcuts_spacy_compiled():
    spacy = pytest.importorskip("spacy", minversion="2.1")
    nlp = spacy.load("en_core_web_sm")
    tmp = tempfile.NamedTemporaryFile(mode="w",
                                      encoding="UTF-8",
                                      suffix=".jsonl",
                                      delete=False)
    patterns = rita.compile("examples/color-car.rita")
    for pattern in patterns:
        tmp.write(json.dumps(pattern) + "\n")
    tmp.flush()
    tmp.close()
    setup_spacy(nlp, patterns=tmp.name)
    os.unlink(tmp.name)
Ejemplo n.º 4
0
def test_shortcuts_spacy_giving_no_rules():
    spacy = pytest.importorskip("spacy", minversion="2.1")
    nlp = spacy.load("en_core_web_sm")
    with pytest.raises(RuntimeError):
        setup_spacy(nlp)
Ejemplo n.º 5
0
def test_shortcuts_spacy_file():
    spacy = pytest.importorskip("spacy", minversion="2.1")
    nlp = spacy.load("en_core_web_sm")
    setup_spacy(nlp, rules_path="examples/color-car.rita")