def discoverObject(object):

    print(Mag + "Building concept to search KB for" + st, object.lemma_)

    features = languageTools.extractFeatures(object)
    facts = [["inst", "?x", object.lemma_]]
    for f in features:
        type = kb.whatAmI(f.lemma_)
        facts.append([type, "?x", f.lemma_])
    print(Mag + "Looking for an ?x that matches:" + st)
    for f in facts:
        print("     ", f)
    bindings = kb.betterAsk(facts)
    if len(bindings) != 1:
        if object.text[-1] == "s":
            print(Mag + "Found reference in KB:")
            elements = [a for a in map(lambda x: x["?x"], bindings)]
            recentMemory.addElements(object.lemma_, elements)
            return elements
        else:
            print(
                Mag +
                "We have a problem with too many objects matching in the KB" +
                st)
    elif bindings == False:
        print(
            Mag +
            "We have a problem because nothing matches these facts in the KB" +
            st)
    else:
        print(Mag + "Found reference in KB:" + st, bindings[0]["?x"])
        recentMemory.addElements(object.lemma_, [bindings[0]["?x"]])
        return [bindings[0]["?x"]]
def discoverQuantifiedObjects(object):

    count_number = utilities.countNumber(False,object)
    reference = languageTools.trackReference(object)

    print(Cyn+"Building concept to search KB for"+st,object.lemma_, "'"+reference.lemma_+"'")

    features = languageTools.extractFeatures(object)
    facts = [["inst","?x",reference.lemma_]]
    for f in features:
        type = kb.whatAmI(f.lemma_)
        facts.append([type,"?x",f.lemma_])
    print(rd+"Looking for an ?x that matches:"+st)
    for f in facts:
        print("     ",f)
    bindings=kb.betterAsk(facts)
    if len(bindings) < count_number:
        print(Cyn+"We have a problem with too few objects matching in the KB"+st)
    elif bindings == False:
        print(Cyn+"We have a problem because nothing matches these facts in the KB"+st)
    else:
        print(Cyn+"Found references in KB:")
        print(Cyn+"Selecting a subset from",len(bindings),"elements")
        candidates = [a for a in map(lambda x: x["?x"], bindings)]
        print(longTermMemory)
        remaining = longTermMemory.getElementAndStatus(reference.lemma_, "remaining")
        if remaining:
            candidates = [a for a in filter(lambda x: x in remaining, candidates)]
            print(Cyn+"Filtering off of last statement")
        names = candidates[0:count_number]
        others = candidates[count_number:]
        print(Cyn+"Selected"+st, names)
        recentMemory.addElements(reference.lemma_, names)
        recentMemory.addElementAndStatus(reference.lemma_, others, "remaining")
        return names
def discoverObject(object):

    print(Mag+"Building concept to search KB for"+st,object.lemma_)

    features = languageTools.extractFeatures(object)
    facts = [["inst","?x",object.lemma_]]
    for f in features:
        type = kb.whatAmI(f.lemma_)
        facts.append([type,"?x",f.lemma_])
    print(Mag+"Looking for an ?x that matches:"+st)
    for f in facts:
        print("     ",f)
    bindings=kb.betterAsk(facts)
    if len(bindings) != 1:
        if object.text[-1] == "s":
            print(Mag+"Found reference in KB:")
            elements = [a for a in map(lambda x: x["?x"], bindings)]
            recentMemory.addElements(object.lemma_,elements)
            return elements
        else:
            print(Mag+"We have a problem with too many objects matching in the KB"+st)
    elif bindings == False:
        print(Mag+"We have a problem because nothing matches these facts in the KB"+st)
    else:
        print(Mag+"Found reference in KB:"+st,bindings[0]["?x"])
        recentMemory.addElements(object.lemma_,[bindings[0]["?x"]])
        return [bindings[0]["?x"]]
def discoverQuantifiedObjects(object):

    count_number = utilities.countNumber(False,object)
    reference = languageTools.trackReference(object)

    print(Cyn+"Building concept to search KB for"+st,object.lemma_, "'"+reference.lemma_+"'")

    features = languageTools.extractFeatures(object)
    facts = [["inst","?x",reference.lemma_]]
    for f in features:
        type = kb.whatAmI(f.lemma_)
        facts.append([type,"?x",f.lemma_])
    print(rd+"Looking for an ?x that matches:"+st)
    for f in facts:
        print("     ",f)
    bindings=kb.betterAsk(facts)
    if len(bindings) < count_number:
        print(Cyn+"We have a problem with too few objects matching in the KB"+st)
    elif bindings == False:
        print(Cyn+"We have a problem because nothing matches these facts in the KB"+st)
    else:
        print(Cyn+"Found references in KB:")
        print(Cyn+"Selecting a subset from",len(bindings),"elements")
        candidates = [a for a in map(lambda x: x["?x"], bindings)]
        print(longTermMemory)
        remaining = longTermMemory.getElementAndStatus(reference.lemma_, "remaining")
        if remaining:
            candidates = [a for a in filter(lambda x: x in remaining, candidates)]
            print(Cyn+"Filtering off of last statement")
        names = candidates[0:count_number]
        others = candidates[count_number:]
        print(Cyn+"Selected"+st, names)
        recentMemory.addElements(reference.lemma_, names)
        recentMemory.addElementAndStatus(reference.lemma_, others, "remaining")
        return names
def findAndAssertFeaturesFOPC(object, names):
    print(Ylw + "Checking features to modify" + st, names)
    features = languageTools.extractFeatures(object)
    for feature in features:
        print(Ylw + "Found" + st, feature)
        feature_type = kb.whatAmI(feature.lemma_)
        for name in names:
            kb.assertFromStatement([feature_type, name, feature.lemma_])
            statements.append([feature_type, name, feature.lemma_])
def findAndAssertFeaturesFOPC(object,names):
    print(Ylw+"Checking features to modify"+st, names)
    features = languageTools.extractFeatures(object)
    for feature in features:
        print(Ylw+"Found"+st,feature)
        feature_type = kb.whatAmI(feature.lemma_)
        for name in names:
            kb.assertFromStatement([feature_type, name, feature.lemma_])
            statements.append([feature_type, name, feature.lemma_])