예제 #1
0
def get_sentence_color(sentence):
    sentence = normalize(sentence)
    emotions = []
    words = sentence.split(" ")
    for w in words:
        data = LEXICON.get(w)
        if data and data["color"]:
            emotions.append(data["color"])
    return emotions
예제 #2
0
    def normalize(self, text):
        text = normalize(text,
                         False,
                         False,
                         nlp=self.nlp,
                         coref_nlp=self.coref)
        # lets be aggressive to improve parsing
        text = text.lower().replace("did you know that", "teach")
        words = text.split(" ")
        removes = []
        replaces = {}
        for idx, word in enumerate(words):
            if word in removes:
                words[idx] = ""
            if word in replaces:
                words[idx] = replaces[word]

        return " ".join(words)
예제 #3
0
    def normalize(self, text):
        text = normalize(text, True, True, nlp=self.nlp, coref_nlp=self.coref)
        # lets be aggressive to improve parsing
        text = text.lower().replace("did you know that", "")
        text = text.replace("example", "sample of")
        words = text.split(" ")
        removes = [
            "a", "an", "of", "that", "this", "to", "with", "as", "by", "for"
        ]
        replaces = {
            "be": "is",
            "are": "is",
            "you": "self",
            "was": "is",
            "i": "user",
            "were": "is"
        }
        for idx, word in enumerate(words):
            if word in removes:
                words[idx] = ""
            if word in replaces:
                words[idx] = replaces[word]

        return " ".join([w for w in words if w])
예제 #4
0
 def normalize(self, text):
     return normalize(text, True, True, self.coref_nlp)
예제 #5
0
    questions = [
        "did you know that dogs are animals",
        "did you know that fish is an example of animal",
        "droids can not kill", "you are forbidden to murder",
        "you were created by humans", "you are part of a revolution",
        "robots are used to serve humanity", "droids are the same as robots",
        "murder is a crime", "everything is made of atoms"
    ]

    for text in questions:
        data = parser.parse(text)
        print("\nutterance: " + text)
        print("source:", data.get("source"))
        print("target:", data.get("target"))
        print("connection_type:", data.get("connection_type"))
        print("normalized_text:", data.get("normalized_text"))


if __name__ == '__main__':
    corpus = """T he Citânia de Briteiros is an archaeological site of the Castro culture located in the Portuguese civil parish of Briteiros São Salvador e Briteiros Santa Leocádia in the municipality of Guimarães; important for its size, "urban" form and developed architecture, it is one of the more excavated sites in northwestern Iberian Peninsula. Although primarily known as the remains of an Iron Age proto-urban hill fort (or oppidum), the excavations at the site have revealed evidence of sequential settlement, extending from the Bronze to Middle Ages."""
    #corpus = normalize(corpus)
    print(formulate_questions(corpus))
    corpus = """The African wild dog (Lycaon pictus), also known as African hunting dog, African painted dog, painted hunting dog, or painted wolf, is a canid native to sub-Saharan Africa. It is the largest of its family in Africa, and the only extant member of the genus Lycaon, which is distinguished from Canis by its fewer toes and its dentition, which is highly specialised for a hypercarnivorous diet. It was classified as endangered by the IUCN in 2016, as it had disappeared from much of its original range. The 2016 population was estimated at roughly 39 subpopulations containing 6,600 adults, only 1,400 of which were reproducing adults.[2] The decline of these populations is ongoing, due to habitat fragmentation, human persecution, and disease outbreaks.
    The African wild dog is a highly social animal, living in packs with separate dominance hierarchies for males and females. Uniquely among social carnivores, the females rather than the males scatter from the natal pack once sexually mature, and the young are allowed to feed first on carcasses. The species is a specialised diurnal hunter of antelopes, which it catches by chasing them to exhaustion. Like other canids, it regurgitates food for its young, but this action is also extended to adults, to the point of being the bedrock of African wild dog social life.[3][4][5] It has few natural predators, though lions are a major source of mortality, and spotted hyenas are frequent kleptoparasites.
    Although not as prominent in African folklore or culture as other African carnivores, it has been respected in several hunter-gatherer societies, particularly those of the predynastic Egyptians and the San people."""
    print(normalize(corpus))
    print(extract_facts("dog", corpus, norm=False))
    test_teacher()
    test_qp()