Ejemplo n.º 1
0
def make_hierarchical_conflict():
    """ Creates two Nile intents that contradict each other due to group hierarchy """
    sentence_entities = {"id": "stn", "operations": []}
    hypothesis_entities = {"id": "hyp", "operations": []}
    sentence_entities, hypothesis_entities = sample_hierarchical_endpoints(
        sentence_entities, hypothesis_entities)
    option = randint(0, 3)
    if option == 0:
        sentence_entities, hypothesis_entities = sample_conflicting_chaining(
            sentence_entities, hypothesis_entities)
    elif option == 1:
        sentence_entities, hypothesis_entities = sample_conflicting_rules(
            sentence_entities, hypothesis_entities)
    elif option == 2:
        sentence_entities, hypothesis_entities = sample_conflicting_qos(
            sentence_entities,
            hypothesis_entities,
            stn_action='set',
            hyp_action='unset')

    conflict = {
        'type': 'hierarchical',
        'sentence': builder.build(sentence_entities),
        'hypothesis': builder.build(hypothesis_entities),
        'conflict': 1
    }
    return conflict
Ejemplo n.º 2
0
def make_time_conflict():
    """ Creates two Nile intents that contradict each other due to time constraints"""
    sentence_entities = {"id": "stn", "operations": []}
    hypothesis_entities = {"id": "hyp", "operations": []}
    sentence_entities, hypothesis_entities = sample_conflicting_endpoints(
        sentence_entities, hypothesis_entities)

    option = randint(0, 2)
    if option == 0:
        sentence_entities, hypothesis_entities = sample_conflicting_chaining(
            sentence_entities, hypothesis_entities)
    elif option == 1:
        sentence_entities, hypothesis_entities = sample_conflicting_rules(
            sentence_entities, hypothesis_entities)
    else:
        sentence_entities, hypothesis_entities = sample_conflicting_qos(
            sentence_entities, hypothesis_entities)

    # start/end
    sentence_entities, hypothesis_entities = sample_conflicting_timeranges(
        sentence_entities, hypothesis_entities)

    conflict = {
        'type': 'time',
        'sentence': builder.build(sentence_entities),
        'hypothesis': builder.build(hypothesis_entities),
        'conflict': 1
    }
    return conflict
Ejemplo n.º 3
0
def make_qos_conflict():
    """ Creates two Nile intents that contradict each other due to qos constraints """
    sentence_entities = {"id": "stn", "operations": []}
    hypothesis_entities = {"id": "hyp", "operations": []}

    if randint(0, 2) % 2 == 0:
        sentence_entities, hypothesis_entities = sample_conflicting_endpoints(
            sentence_entities, hypothesis_entities)
    else:
        sentence_entities, hypothesis_entities = sample_hierarchical_endpoints(
            sentence_entities, hypothesis_entities)

    if randint(0, 2) % 2 == 0:
        sentence_entities, hypothesis_entities = sample_conflicting_qos(
            sentence_entities, hypothesis_entities)
    else:
        sentence_entities, hypothesis_entities = sample_conflicting_qos(
            sentence_entities,
            hypothesis_entities,
            stn_action='set',
            hyp_action='unset')

    conflict = {
        'type': 'qos',
        'sentence': builder.build(sentence_entities),
        'hypothesis': builder.build(hypothesis_entities),
        'conflict': 1
    }
    return conflict
Ejemplo n.º 4
0
def make_synonym_entailment():
    """ Creates two Nile intents that entail each other with synonyms use """
    sentence_entities = {"id": "stn", "operations": []}
    hypothesis_entities = {"id": "hyp", "operations": []}
    sentence_entities, hypothesis_entities = sample_synonyms_endpoints(
        sentence_entities, hypothesis_entities)
    option = randint(0, 2)
    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')

    entailment = {
        'type': 'synonym',
        'sentence': builder.build(sentence_entities),
        'hypothesis': builder.build(hypothesis_entities),
        'conflict': 0
    }

    return entailment
Ejemplo n.º 5
0
def make_path_conflict():
    """ Creates two Nile intents that contradict each other due to path overlap"""
    sentence_entities = {"id": "stn", "operations": []}
    hypothesis_entities = {"id": "hyp", "operations": []}

    sentence_entities, hypothesis_entities = sample_conflicting_endpoints(
        sentence_entities, hypothesis_entities)

    option = randint(0, 2)
    if option == 0:
        sentence_entities, hypothesis_entities = sample_conflicting_chaining(
            sentence_entities, hypothesis_entities)
    elif option == 1:
        sentence_entities, hypothesis_entities = sample_conflicting_rules(
            sentence_entities, hypothesis_entities)
    elif option == 2:
        sentence_entities, hypothesis_entities = sample_conflicting_qos(
            sentence_entities,
            hypothesis_entities,
            stn_action='set',
            hyp_action='unset')

    entailment = {
        'type': 'path',
        'sentence': builder.build(sentence_entities),
        'hypothesis': builder.build(hypothesis_entities),
        'conflict': 1
    }
    return entailment
Ejemplo n.º 6
0
def make_qos_entailment():
    """ Creates two Nile intents that entail each other with qos constraints """
    sentence_entities = {"id": "stn", "operations": []}
    hypothesis_entities = {"id": "hyp", "operations": []}

    sentence_entities, hypothesis_entities = sample_conflicting_endpoints(
        sentence_entities, hypothesis_entities)
    sentence_entities, hypothesis_entities = sample_entailing_qos(
        sentence_entities, hypothesis_entities)

    entailment = {
        'type': 'qos',
        'sentence': builder.build(sentence_entities),
        'hypothesis': builder.build(hypothesis_entities),
        'conflict': 0
    }
    return entailment
Ejemplo n.º 7
0
def make_time_entailment():
    """ Creates two Nile intents that entail each other with time constraints"""
    sentence_entities = {"id": "stn", "operations": []}
    hypothesis_entities = {"id": "hyp", "operations": []}
    sentence_entities, hypothesis_entities = sample_conflicting_endpoints(
        sentence_entities, hypothesis_entities)
    option = randint(0, 2)
    if option == 0:
        # middleboxes
        if randint(1, 10) % 2 == 0:
            sentence_entities, hypothesis_entities = sample_entailing_chaining(
                sentence_entities, hypothesis_entities)
        else:
            sentence_entities, hypothesis_entities = sample_conflicting_chaining(
                sentence_entities, hypothesis_entities)
    elif option == 1:
        # 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_conflicting_rules(
                sentence_entities, hypothesis_entities)
    elif option == 2:
        # allow/block
        if randint(1, 10) % 2 == 0:
            sentence_entities, hypothesis_entities = sample_entailing_qos(
                sentence_entities, hypothesis_entities)
        else:
            sentence_entities, hypothesis_entities = sample_conflicting_qos(
                sentence_entities, hypothesis_entities)

    # start/end
    sentence_entities, hypothesis_entities = sample_entailing_timeranges(
        sentence_entities, hypothesis_entities)

    entailment = {
        'type': 'time',
        'sentence': builder.build(sentence_entities),
        'hypothesis': builder.build(hypothesis_entities),
        'conflict': 0
    }
    return entailment
Ejemplo n.º 8
0
def make_negation_entailment():
    """ Creates two Nile intents that entail each other with negation """

    sentence_entities = {"id": "stn", "operations": []}
    hypothesis_entities = {"id": "hyp", "operations": []}
    sentence_entities, hypothesis_entities = sample_conflicting_endpoints(
        sentence_entities, hypothesis_entities)

    option = randint(0, 2)
    if option == 0:
        # add/remove
        sentence_entities, hypothesis_entities = sample_entailing_chaining(
            sentence_entities, hypothesis_entities)
    elif option == 1:
        # allow/block
        sentence_entities, hypothesis_entities = sample_entailing_rules(
            sentence_entities, hypothesis_entities)
    elif option == 2:
        # set/unset
        sentence_entities, hypothesis_entities = sample_entailing_qos(
            sentence_entities,
            hypothesis_entities,
            stn_action='set',
            hyp_action='unset')

    if 'allow' in sentence_entities[
            'operations'] or 'block' in sentence_entities['operations']:
        if randint(0, 2) % 2 == 0:
            sentence_entities['operations'].append('add')
            sentence_entities['middleboxes'] = ['firewall']

        if randint(0, 2) % 2 == 0:
            hypothesis_entities['operations'].append('add')
            hypothesis_entities['middleboxes'] = ['firewall']

    entailment = {
        'type': 'negation',
        'sentence': builder.build(sentence_entities),
        'hypothesis': builder.build(hypothesis_entities),
        'conflict': 0
    }
    return entailment
Ejemplo n.º 9
0
def make_mixed_intent():
    """ Creates a Nile intent with mixed intents"""
    sentence_entities = {"id": "stn", "operations": []}
    hypothesis_entities = {"id": "hyp", "operations": []}
    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': builder.build(sentence_entities),
    }
    return intent
Ejemplo n.º 10
0
def make_path_entailment():
    """ Creates two Nile intents that entail each other due to non coference"""
    sentence_entities = {"id": "stn", "operations": []}
    hypothesis_entities = {"id": "hyp", "operations": []}

    option = randint(0, 2)
    if option == 0:
        sentence_entities = make_sfc_intent(True)
        hypothesis_entities = make_acl_intent(True)
    elif option == 1:
        sentence_entities = make_qos_intent(True)
        hypothesis_entities = make_acl_intent(True)
    elif option == 2:
        sentence_entities = make_qos_intent(True)
        hypothesis_entities = make_sfc_intent(True)

    entailment = {
        'type': 'path',
        'sentence': builder.build(sentence_entities),
        'hypothesis': builder.build(hypothesis_entities),
        'conflict': 0
    }
    return entailment
Ejemplo n.º 11
0
def make_temporal_intent(return_entities=False):
    """ Creates a Nile intent with time"""
    sentence_entities = {"id": "stn", "operations": []}
    hypothesis_entities = {"id": "hyp", "operations": []}
    sentence_entities, _ = sample_entailing_endpoints(sentence_entities,
                                                      hypothesis_entities)
    sentence_entities, _ = sample_entailing_timeranges(sentence_entities,
                                                       hypothesis_entities)

    if return_entities:
        return sentence_entities

    intent = {
        'type': 'temporal',
        'nile': builder.build(sentence_entities),
    }
    return intent
Ejemplo n.º 12
0
def make_acl_intent(return_entities=False):
    """ Creates a Nile intent with acl"""
    sentence_entities = {"id": "stn", "operations": []}
    hypothesis_entities = {"id": "hyp", "operations": []}
    sentence_entities, _ = sample_entailing_endpoints(sentence_entities,
                                                      hypothesis_entities)
    sentence_entities, _ = sample_conflicting_rules(sentence_entities,
                                                    hypothesis_entities)

    if return_entities:
        return sentence_entities

    intent = {
        'type': 'acl',
        'nile': builder.build(sentence_entities),
    }
    return intent
Ejemplo n.º 13
0
def feedback_confirm(request):
    """ Webhook action to confirm feedback received from the user """

    uuid = request.get("session").split("/")[-1]
    db = client.Database()
    intent = db.get_latest_intent(uuid)

    print("INTENT CONFIRM", intent)
    entities = intent['entities']
    for entity, values in intent["missingEntities"].items():
        entity_key = entity
        if entity == "middlebox":
            entity_key = "middleboxes"
        elif entity == "service":
            entity_key = "services"
        elif entity == "traffic":
            entity_key = "traffics"
        elif entity == "protocol":
            entity_key = "protocols"
        elif entity == "operation":
            entity_key = "operations"
        elif entity == "location":
            entity_key = "locations"

        if entity_key not in entities:
            entities[entity_key] = list(values.keys())
        else:
            entities[entity_key] += list(values.keys())

    try:
        nile = builder.build(entities)
        speech = "So, is this what you want then?"
        response = make_card_response("Nile Intent", nile, speech, beautify_intent(nile),
                                      suggestions=["Yes", "No"])

        # tracking
        db.update_intent(intent["_id"], {"status": "pending", "nileFeedback": nile})
    except ValueError as err:
        traceback.print_exc()
        # TODO: use slot-filling to get the missing info
        # TODO: use different exceptions to figure out whats missing
        response = make_simple_response("{}".format(err))

    return response
Ejemplo n.º 14
0
def make_qos_intent(return_entities=False):
    """ Creates a Nile intent with qos"""
    sentence_entities = {"id": "stn", "operations": []}
    hypothesis_entities = {"id": "hyp", "operations": []}
    sentence_entities, _ = sample_entailing_endpoints(sentence_entities,
                                                      hypothesis_entities)
    sentence_entities, _ = sample_entailing_qos(sentence_entities,
                                                hypothesis_entities,
                                                stn_action='set',
                                                hyp_action='unset')

    if return_entities:
        return sentence_entities

    intent = {
        'type': 'qos',
        'nile': builder.build(sentence_entities),
    }
    return intent
Ejemplo n.º 15
0
def build_nile_intent(request):
    """ Webhook action to build Nile intent from Dialogflow request """
    uuid = request.get("session").split("/")[-1]
    text = request.get("queryResult").get("queryText")

    response = {}
    try:
        entities = parse_entities(request)
        intent = builder.build(entities)
        speech = "Is this what you want?"
        response = make_card_response("Nile Intent", intent, speech, beautify_intent(intent),
                                      suggestions=["Yes", "No"])

        # tracking
        db = client.Database()
        db.insert_intent(uuid, text, entities, intent)
    except ValueError as err:
        traceback.print_exc()
        # TODO: use slot-filling to get the missing info
        # TODO: use different exceptions to figure out whats missing
        response = make_simple_response("{}".format(err))

    return response