Exemple #1
0
 def setup_class(cls):
     data_dict = {
         "greet": [
             "Hello",
             "Hello!",
             "hey",
             "what's up",
             "greetings",
             "yo",
             "hi",
             "hey, how are you?",
             "hola",
             "start",
         ],
         "exit": [
             "bye",
             "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 = ProcessedQueryList.from_in_memory_list(labeled_data)
Exemple #2
0
def test_processed_query_list(resource_loader):
    queries = resource_loader.get_flattened_label_set()
    # verify that the query cache is correct
    assert queries.cache == resource_loader.query_cache

    # test sqlite backed list
    _run_tests_on_pql(queries)

    # test in-memory list
    mem_pql = ProcessedQueryList.from_in_memory_list(
        list(queries.processed_queries()))
    assert isinstance(mem_pql.cache, ProcessedQueryList.MemoryCache)
    _run_tests_on_pql(mem_pql)
Exemple #3
0
 def setup_class(cls):
     examples = [
         "make that {one|sys_number|num_orders} plate of {vegetable lumpia|dish} and "
         "{ten|sys_number|num_orders} orders of {pork sasig|dish}",
         "{lamb curry|dish} with a {side of rice|option} from the {burmese cafe|restaurant}",
         "i'll get a {normal cheese pizza|dish} with {extra cheese|option} and "
         "{extra sauce|option}",
         "What do you have for {dinner|category}?",
         "i want a {half ramen and omusubi|dish} pork",
         "{appetizers|category}",
         "can i get a {regular poki bowl|dish} with {tuna|option} and {yellow tail|option}",
         "I'd like the {Tabouleh|dish} with {feta cheese|option}, {dolmas|dish} "
         "and a {prawn kebab plate|dish} from {saffron 685|restaurant}.",
         "add an order of {tea|dish}",
         "{Half tofu barbeque pork|dish} and a {coconut water|dish}",
         "add an order of {tea|dish} from {Sallys|restaurant}",
         "i feel like having some {Kale Caesar Salad|dish}",
         "i would like to order from {k-oz restaurant|restaurant}",
         "Can I get some {south indian|cuisine} food delivered in 30 min?",
         "{Chorizo con huevos|dish} {without beans|option}",
         "Can I get a {lamb curry|dish} with a side of {brown rice|option} and {raita|option}?",
         "can you recommend some {Japan|cuisine} restaurants which are highly reviewed but not "
         "that expensive",
         "add the {spicy poke sauce|option}",
         "{basil eggplant with chicken and prawns|dish}",
         "{blt|dish} with {egg|option}, make it with {wheat bread|option}",
         "{blackened catfish|dish} with {no sweet potatoes|category}",
         "{1|sys_number|num_orders} order of {samosa|dish}, {1|sys_number|num_orders} "
         "{baingan bartha|dish}, {1|sys_number|num_orders} {chicken achar|dish}, "
         "{2|sys_number|num_orders} {onion naans|dish} and {1|sys_number|num_orders} "
         "{kheema naan|dish}",
         "can i order a {mimosa|dish} {brunch|category}?",
         "get me something from {Dinosaurs Vietnamese Sandwiches|restaurant}",
         "what kind of {fish|option} dishes are there",
         "From {burma cafe|restaurant}, I'll get the {pumpkin curry|dish} with "
         "{coconut rice|option}",
         "Can I add get {3|sys_number|num_orders} {guaranas|dish} to that?",
         "Could you add a {dozen|sys_number|num_orders} {sesame cookies|dish}?",
         "Give me some of that {pork sisig|dish}",
         "Give me some food please",
         "add that",
         "no expensive food please",
     ]
     labeled_data = [
         markup.load_query(ex, query_factory=QUERY_FACTORY)
         for ex in examples
     ]
     cls.labeled_data = ProcessedQueryList.from_in_memory_list(labeled_data)
Exemple #4
0
def _run_tests_on_pql(queries):
    # verify the correct types are returned by the iterators
    assert isinstance(next(queries.processed_queries()), ProcessedQuery)
    assert isinstance(next(queries.raw_queries()), str)
    assert isinstance(next(queries.queries()), Query)
    assert isinstance(next(queries.entities())[0], NestedEntity)
    assert isinstance(next(queries.domains()), str)
    assert isinstance(next(queries.intents()), str)
    int_iterator = ProcessedQueryList.ListIterator(list(range(len(queries))))
    assert isinstance(next(int_iterator), int)

    # verify the domains are correct
    assert set(queries.domains()) == {"banking", "store_info"}

    # verify the intents are correct
    assert set(queries.intents()) == {
        "transfer_money", "greet", "get_store_number", "find_nearest_store",
        "exit", "get_store_hours", "help"
    }

    def test_reordering(iterator):
        # verify that reordering works properly
        indices = list(range(len(iterator)))
        indices.reverse()
        _reversed = list(iterator)
        _reversed.reverse()
        iterator.reorder(indices)
        for q1, q2 in zip(_reversed, iterator):
            assert q1 == q2

    # uncached iterator
    test_reordering(queries.raw_queries())
    # cached iterator
    test_reordering(queries.intents())
    # custom list iterator
    test_reordering(int_iterator)