Example #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)
Example #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
Example #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)
Example #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)
Example #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")