def make_negation_entailment(): """ Creates two Nile intents that entail each other with negation """ sentence_entities = {"id": "stn", "actions": []} hypothesis_entities = {"id": "hyp", "actions": []} sentence_entities, hypothesis_entities = sample_contradicting_endpoints( sentence_entities, hypothesis_entities) # middleboxes sentence_entities, hypothesis_entities = sample_entailing_chaining( sentence_entities, hypothesis_entities) # allow/block sentence_entities, hypothesis_entities = sample_entailing_rules( sentence_entities, hypothesis_entities) # set/unset sentence_entities, hypothesis_entities = sample_entailing_qos( sentence_entities, hypothesis_entities, stn_action='set', hyp_action='unset') entailment = { 'type': 'negation', 'sentence': interpreter.translate(sentence_entities), 'hypothesis': interpreter.translate(hypothesis_entities), 'contradiction': 0 } return entailment
def make_time_entailment(): """ Creates two Nile intents that entail each other with time constraints""" sentence_entities = {"id": "stn", "actions": []} hypothesis_entities = {"id": "hyp", "actions": []} sentence_entities, hypothesis_entities = sample_contradicting_endpoints( sentence_entities, hypothesis_entities) # middleboxes if randint(1, 10) % 2 == 0: sentence_entities, hypothesis_entities = sample_entailing_chaining( sentence_entities, hypothesis_entities) else: sentence_entities, hypothesis_entities = sample_contradicting_chaining( sentence_entities, hypothesis_entities) # allow/block if randint(1, 10) % 2 == 0: sentence_entities, hypothesis_entities = sample_entailing_rules( sentence_entities, hypothesis_entities) else: sentence_entities, hypothesis_entities = sample_contradicting_rules( sentence_entities, hypothesis_entities) # start/end sentence_entities, hypothesis_entities = sample_entailing_timeranges( sentence_entities, hypothesis_entities) entailment = { 'type': 'time', 'sentence': interpreter.translate(sentence_entities), 'hypothesis': interpreter.translate(hypothesis_entities), 'contradiction': 0 } return entailment
def make_hierarchical_entailment(): """ Creates two Nile intents that entail each other with group hierarchy """ sentence_entities = {"id": "stn", "actions": []} hypothesis_entities = {"id": "hyp", "actions": []} sentence_entities, hypothesis_entities = sample_hierarchical_endpoints( sentence_entities, hypothesis_entities) option = randint(0, 7) if option == 0: sentence_entities, hypothesis_entities = sample_entailing_chaining( sentence_entities, hypothesis_entities) elif option == 1: sentence_entities, hypothesis_entities = sample_entailing_rules( sentence_entities, hypothesis_entities) elif option == 2: sentence_entities, hypothesis_entities = sample_entailing_qos( sentence_entities, hypothesis_entities, stn_action='set', hyp_action='unset') if option == 3: sentence_entities, hypothesis_entities = sample_entailing_chaining( sentence_entities, hypothesis_entities) sentence_entities, hypothesis_entities = sample_entailing_rules( sentence_entities, hypothesis_entities) elif option == 4: sentence_entities, hypothesis_entities = sample_entailing_rules( sentence_entities, hypothesis_entities) sentence_entities, hypothesis_entities = sample_entailing_qos( sentence_entities, hypothesis_entities, stn_action='set', hyp_action='unset') elif option == 5: sentence_entities, hypothesis_entities = sample_entailing_chaining( sentence_entities, hypothesis_entities) sentence_entities, hypothesis_entities = sample_entailing_qos( sentence_entities, hypothesis_entities, stn_action='set', hyp_action='unset') else: sentence_entities, hypothesis_entities = sample_entailing_chaining( sentence_entities, hypothesis_entities) sentence_entities, hypothesis_entities = sample_entailing_rules( sentence_entities, hypothesis_entities) sentence_entities, hypothesis_entities = sample_entailing_qos( sentence_entities, hypothesis_entities, stn_action='set', hyp_action='unset') entailment = { 'type': 'hierarchical', 'sentence': interpreter.translate(sentence_entities), 'hypothesis': interpreter.translate(hypothesis_entities), 'contradiction': 0 } return entailment
def make_domain_contradiction(): """ Creates two Nile intents that contradict each other due to domains """ sentence_entities = {"id": "stn", "actions": []} hypothesis_entities = {"id": "hyp", "actions": []} sentence_entities, hypothesis_entities = sample_contradicting_endpoints( sentence_entities, hypothesis_entities, mixed=True) option = randint(0, 7) if option == 0: sentence_entities, hypothesis_entities = sample_contradicting_chaining( sentence_entities, hypothesis_entities) elif option == 1: sentence_entities, hypothesis_entities = sample_contradicting_rules( sentence_entities, hypothesis_entities) elif option == 2: sentence_entities, hypothesis_entities = sample_contradicting_qos( sentence_entities, hypothesis_entities, stn_action='set', hyp_action='unset') if option == 3: sentence_entities, hypothesis_entities = sample_contradicting_chaining( sentence_entities, hypothesis_entities) sentence_entities, hypothesis_entities = sample_contradicting_rules( sentence_entities, hypothesis_entities) elif option == 4: sentence_entities, hypothesis_entities = sample_contradicting_rules( sentence_entities, hypothesis_entities) sentence_entities, hypothesis_entities = sample_contradicting_qos( sentence_entities, hypothesis_entities, stn_action='set', hyp_action='unset') elif option == 5: sentence_entities, hypothesis_entities = sample_contradicting_chaining( sentence_entities, hypothesis_entities) sentence_entities, hypothesis_entities = sample_contradicting_qos( sentence_entities, hypothesis_entities, stn_action='set', hyp_action='unset') else: sentence_entities, hypothesis_entities = sample_contradicting_chaining( sentence_entities, hypothesis_entities) sentence_entities, hypothesis_entities = sample_contradicting_rules( sentence_entities, hypothesis_entities) sentence_entities, hypothesis_entities = sample_contradicting_qos( sentence_entities, hypothesis_entities, stn_action='set', hyp_action='unset') contradiction = { 'type': 'domain', 'sentence': interpreter.translate(sentence_entities), 'hypothesis': interpreter.translate(hypothesis_entities), 'contradiction': 1 } return contradiction
def make_qos_entailment(): """ Creates two Nile intents that entail each other with qos constraints """ sentence_entities = {"id": "stn", "actions": []} hypothesis_entities = {"id": "hyp", "actions": []} sentence_entities, hypothesis_entities = sample_contradicting_endpoints( sentence_entities, hypothesis_entities) sentence_entities, hypothesis_entities = sample_entailing_qos( sentence_entities, hypothesis_entities) entailment = { 'type': 'qos', 'sentence': interpreter.translate(sentence_entities), 'hypothesis': interpreter.translate(hypothesis_entities), 'contradiction': 0 } return entailment
def make_mixed_intent(): """ Creates a Nile intent with mixed intents""" sentence_entities = {"id": "stn", "actions": []} hypothesis_entities = {"id": "hyp", "actions": []} sentence_entities, _ = sample_entailing_endpoints(sentence_entities, hypothesis_entities) option = randint(0, 7) if option == 0: sentence_entities, _ = sample_entailing_chaining( sentence_entities, hypothesis_entities) elif option == 1: sentence_entities, _ = sample_entailing_rules(sentence_entities, hypothesis_entities) elif option == 2: sentence_entities, _ = sample_entailing_qos(sentence_entities, hypothesis_entities, stn_action='set', hyp_action='unset') if option == 3: sentence_entities, _ = sample_entailing_chaining( sentence_entities, hypothesis_entities) sentence_entities, _ = sample_entailing_rules(sentence_entities, hypothesis_entities) elif option == 4: sentence_entities, _ = sample_entailing_rules(sentence_entities, hypothesis_entities) sentence_entities, _ = sample_entailing_qos(sentence_entities, hypothesis_entities, stn_action='set', hyp_action='unset') elif option == 5: sentence_entities, _ = sample_entailing_chaining( sentence_entities, hypothesis_entities) sentence_entities, _ = sample_entailing_qos(sentence_entities, hypothesis_entities, stn_action='set', hyp_action='unset') else: sentence_entities, _ = sample_entailing_chaining( sentence_entities, hypothesis_entities) sentence_entities, _ = sample_entailing_rules(sentence_entities, hypothesis_entities) sentence_entities, _ = sample_entailing_qos(sentence_entities, hypothesis_entities, stn_action='set', hyp_action='unset') intent = { 'type': 'mixed', 'nile': interpreter.translate(sentence_entities), } return intent
def make_path_entailment(): """ Creates two Nile intents that entail each other due to non coference""" sentence_entities = {"id": "stn", "actions": []} hypothesis_entities = {"id": "hyp", "actions": []} sentence_entities, hypothesis_entities = sample_entailing_endpoints( sentence_entities, hypothesis_entities) if randint(0, 10) % 2 == 0: sentence_entities, hypothesis_entities = sample_entailing_chaining( sentence_entities, hypothesis_entities) else: sentence_entities, hypothesis_entities = sample_contradicting_chaining( sentence_entities, hypothesis_entities) if randint(0, 10) % 2 == 0: sentence_entities, hypothesis_entities = sample_entailing_rules( sentence_entities, hypothesis_entities) else: sentence_entities, hypothesis_entities = sample_contradicting_rules( sentence_entities, hypothesis_entities) if randint(0, 10) % 2 == 0: sentence_entities, hypothesis_entities = sample_entailing_qos( sentence_entities, hypothesis_entities) else: sentence_entities, hypothesis_entities = sample_contradicting_qos( sentence_entities, hypothesis_entities) if randint(0, 10) % 2 == 0: sentence_entities, hypothesis_entities = sample_entailing_timeranges( sentence_entities, hypothesis_entities) entailment = { 'type': 'path', 'sentence': interpreter.translate(sentence_entities), 'hypothesis': interpreter.translate(hypothesis_entities), 'contradiction': 0 } return entailment
def make_temporal_intent(): """ Creates a Nile intent with time""" sentence_entities = {"id": "stn", "actions": []} hypothesis_entities = {"id": "hyp", "actions": []} sentence_entities, _ = sample_entailing_endpoints(sentence_entities, hypothesis_entities) sentence_entities, _ = sample_entailing_timeranges(sentence_entities, hypothesis_entities) intent = { 'type': 'temporal', 'nile': interpreter.translate(sentence_entities), } return intent
def make_acl_intent(): """ Creates a Nile intent with acl""" sentence_entities = {"id": "stn", "actions": []} hypothesis_entities = {"id": "hyp", "actions": []} sentence_entities, _ = sample_entailing_endpoints(sentence_entities, hypothesis_entities) sentence_entities, _ = sample_contradicting_rules(sentence_entities, hypothesis_entities) intent = { 'type': 'acl', 'nile': interpreter.translate(sentence_entities), } return intent
def make_qos_intent(): """ Creates a Nile intent with qos""" sentence_entities = {"id": "stn", "actions": []} hypothesis_entities = {"id": "hyp", "actions": []} sentence_entities, _ = sample_entailing_endpoints(sentence_entities, hypothesis_entities) sentence_entities, _ = sample_entailing_qos(sentence_entities, hypothesis_entities, stn_action='set', hyp_action='unset') intent = { 'type': 'qos', 'nile': interpreter.translate(sentence_entities), } return intent
def build_nile_intent(request): """ Webhook action to build Nile intent from Dialogflow request """ entities = parse_intent(request) intent = interpreter.translate(entities) speech = "Is this what you want?" global training_feedback training_feedback["original_intent"] = request.get("queryResult").get( "queryText") training_feedback["nile_intent"] = intent training_feedback["entities"] = {} response = make_card_response("Nile Intent", intent, speech, beautify_intent(intent)) return response
def make_path_contradiction(): """ Creates two Nile intents that contradict each other due to path overlap""" sentence_entities = {"id": "stn", "actions": []} hypothesis_entities = {"id": "hyp", "actions": []} sentence_entities, hypothesis_entities = sample_contradicting_endpoints( sentence_entities, hypothesis_entities) option = randint(0, 7) # if randint(0, 10) % 2 == 0: # _, hypothesis_entities = sample_contradicting_chaining(sentence_entities, hypothesis_entities) # else: # sentence_entities, _ = sample_contradicting_chaining(sentence_entities, hypothesis_entities) # # if randint(0, 10) % 2 == 0: # sentence_entities, _ = sample_contradicting_rules(sentence_entities, hypothesis_entities) # else: # _, hypothesis_entities = sample_contradicting_chaining(sentence_entities, hypothesis_entities) # # if randint(0, 10) % 2 == 0: # sentence_entities, hypothesis_entities = sample_entailing_qos(sentence_entities, hypothesis_entities) # else: # sentence_entities, hypothesis_entities = sample_contradicting_qos(sentence_entities, hypothesis_entities) # # if randint(0, 10) % 2 == 0: # sentence_entities, hypothesis_entities = sample_entailing_timeranges(sentence_entities, hypothesis_entities) if option == 0: sentence_entities, hypothesis_entities = sample_contradicting_chaining( sentence_entities, hypothesis_entities) elif option == 1: sentence_entities, hypothesis_entities = sample_contradicting_rules( sentence_entities, hypothesis_entities) elif option == 2: sentence_entities, hypothesis_entities = sample_contradicting_qos( sentence_entities, hypothesis_entities, stn_action='set', hyp_action='unset') if option == 3: sentence_entities, hypothesis_entities = sample_contradicting_chaining( sentence_entities, hypothesis_entities) sentence_entities, hypothesis_entities = sample_contradicting_rules( sentence_entities, hypothesis_entities) elif option == 4: sentence_entities, hypothesis_entities = sample_contradicting_rules( sentence_entities, hypothesis_entities) sentence_entities, hypothesis_entities = sample_contradicting_qos( sentence_entities, hypothesis_entities, stn_action='set', hyp_action='unset') elif option == 5: sentence_entities, hypothesis_entities = sample_contradicting_chaining( sentence_entities, hypothesis_entities) sentence_entities, hypothesis_entities = sample_contradicting_qos( sentence_entities, hypothesis_entities, stn_action='set', hyp_action='unset') else: sentence_entities, hypothesis_entities = sample_contradicting_chaining( sentence_entities, hypothesis_entities) sentence_entities, hypothesis_entities = sample_contradicting_rules( sentence_entities, hypothesis_entities) sentence_entities, hypothesis_entities = sample_contradicting_qos( sentence_entities, hypothesis_entities, stn_action='set', hyp_action='unset') entailment = { 'type': 'path', 'sentence': interpreter.translate(sentence_entities), 'hypothesis': interpreter.translate(hypothesis_entities), 'contradiction': 0 } return entailment