How to use the mindmeld.markup.load_query function in mindmeld

To help you get started, we’ve selected a few mindmeld examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cisco / mindmeld / tests / models / test_text_models.py View on Github external
"model_settings": {"classifier_type": "logreg"},
                "params": {"fit_intercept": True, "C": 100},
                "features": {
                    "bag-of-words": {"lengths": [1]},
                    "freq": {"bins": 5},
                    "length": {},
                },
            }
        )
        model = TextModel(config)
        examples = [q.query for q in self.labeled_data]
        labels = [q.intent for q in self.labeled_data]
        model.initialize_resources(resource_loader, examples, labels)
        model.fit(examples, labels)

        assert model.predict([markup.load_query("hi").query]) == "greet"
        assert model.predict([markup.load_query("bye").query]) == "exit"
github cisco / mindmeld / tests / test_markup.py View on Github external
def test_load_special_chars_2(query_factory):
    """Tests loading a query with special characters"""
    text = "what's on at {{8 p.m.|sys_time}|range}?"
    processed_query = markup.load_query(text, query_factory)
    entities = processed_query.entities

    assert len(entities) == 1

    entity = entities[0]
    assert entity.text == "8 p.m."
    assert entity.normalized_text == "8 p m"
    assert entity.span == Span(13, 18)
    assert entity.entity.type == "range"

    nested = entity.entity.value["children"][0]
    assert nested.text == "8 p.m."
    assert nested.span == Span(0, 5)
    assert nested.entity.type == "sys_time"
    assert nested.entity.value["value"]
github cisco / mindmeld / tests / models / test_text_models.py View on Github external
"goodbye",
                "until next time",
                "see ya later",
                "ttyl",
                "talk to you later" "later",
                "have a nice day",
                "finish",
                "gotta go" "I'm leaving",
                "I'm done",
                "that's all",
            ],
        }
        labeled_data = []
        for intent in data_dict:
            for text in data_dict[intent]:
                labeled_data.append(markup.load_query(text, intent=intent))
        cls.labeled_data = labeled_data
github cisco / mindmeld / tests / components / test_parser.py View on Github external
def test_distance(self):
        """Tests the parser attaches dependents to their nearest head"""
        query = markup.load_query("{Hello|head} {there|dependent} my {friend|head}")
        entities = self.parser.parse_entities(query.query, query.entities)

        assert len(entities) == 3
        assert entities[0].children == (entities[1],)
        assert entities[1].parent == entities[0]
        assert entities[2].children is None
github cisco / mindmeld / tests / components / test_parser.py View on Github external
def test_link_word(self):
        """Tests that parser considers link words, overriding default distance calculation."""
        text = (
            "A {pizza|dish} with {olives|option}, {breadsticks|dish} and a {coke|dish}"
        )
        query = markup.load_query(text)
        entities = self.parser.parse_entities(query.query, query.entities)

        assert len(entities) == 4
        assert entities[0].children == (entities[1],)
        assert entities[1].parent == entities[0]
        assert entities[2].children is None
        assert entities[3].children is None
github cisco / mindmeld / tests / components / test_parser.py View on Github external
def test_unconfigured(self):
        """Tests the parser functions when unconfigured entities are present"""
        query = markup.load_query("{Hello|head} {there|other}")
        entities = self.parser.parse_entities(query.query, query.entities)

        assert entities
github cisco / mindmeld / tests / test_markup.py View on Github external
def test_load_nested_3(query_factory):
    """Tests loading a query with a nested system entity"""
    text = "show me houses under {{1.5 million|sys_number} dollars|price}"
    processed_query = markup.load_query(text, query_factory)

    assert processed_query
github cisco / mindmeld / tests / components / test_parser.py View on Github external
def test_left(self):
        """Tests the parser attaches dependents from the left"""
        query = markup.load_query("{Hello|dependent} {there|head}")
        entities = self.parser.parse_entities(query.query, query.entities)

        assert len(entities) == 2
        assert entities[0].parent == entities[1]
        assert entities[1].children == (entities[0],)
github cisco / mindmeld / tests / test_markup.py View on Github external
def test_load_special_chars_3(query_factory):
    """Tests loading a query with special characters"""
    text = "is {s.o.b.|show} gonna be {{on at 8 p.m.|sys_time}|range}?"
    processed_query = markup.load_query(text, query_factory)
    entities = processed_query.entities

    expected_entity = QueryEntity.from_query(
        processed_query.query, Span(3, 8), entity_type="show"
    )
    assert entities[0] == expected_entity

    assert entities[1].entity.type == "range"
    assert entities[1].span == Span(19, 30)
    assert "children" in entities[1].entity.value
    assert entities[1].entity.value["children"][0].entity.type == "sys_time"
github cisco / mindmeld / tests / test_markup.py View on Github external
def test_load_special_chars_6(query_factory):
    """Tests loading a query with special characters"""
    text = "what's on {after {8 p.m.|sys_time}|range}?"
    processed_query = markup.load_query(text, query_factory)
    entities = processed_query.entities

    assert len(entities) == 1

    assert entities[0].text == "after 8 p.m."
    assert entities[0].normalized_text == "after 8 p m"
    assert entities[0].span == Span(10, 21)