def test_most_general_hypernym_ancestor_good_case_homonym_class(self):
     result_set = set()
     for counter in range(1, 20):
         working_ontology = holmes.Ontology(
             os.sep.join((script_directory, 'test_ontology.owl')))
         result_set.add(
             working_ontology.get_most_general_hypernym_ancestor('horse'))
     self.assertEqual(result_set, {'animal'})
Example #2
0
import unittest
import holmes_extractor as holmes
import os
from holmes_extractor.tests.testing_utils import HolmesInstanceManager

script_directory = os.path.dirname(os.path.realpath(__file__))
ontology = holmes.Ontology(os.sep.join(
    (script_directory, 'test_ontology.owl')))
coref_holmes_manager = HolmesInstanceManager(ontology).en_coref_lg_ontology
coref_holmes_manager.register_search_phrase("A dog chases a cat")
coref_holmes_manager.register_search_phrase("A big horse chases a cat")
coref_holmes_manager.register_search_phrase("A tiger chases a little cat")
coref_holmes_manager.register_search_phrase("A big lion chases a cat")
coref_holmes_manager.register_search_phrase("An ENTITYPERSON needs insurance")
coref_holmes_manager.register_search_phrase("University for four years")
coref_holmes_manager.register_search_phrase("A big company makes a loss")
coref_holmes_manager.register_search_phrase(
    "A dog who chases rats chases mice")
coref_holmes_manager.register_search_phrase("A tired dog")
coref_holmes_manager.register_search_phrase("A panther chases a panther")
coref_holmes_manager.register_search_phrase("A leopard chases a leopard")
no_coref_holmes_manager = holmes.Manager(model='en_coref_lg',
                                         ontology=ontology,
                                         perform_coreference_resolution=False)
no_coref_holmes_manager.register_search_phrase("A dog chases a cat")
embeddings_coref_holmes_manager = holmes.Manager(
    model='en_coref_lg', overall_similarity_threshold=0.85)
embeddings_coref_holmes_manager.register_search_phrase('A man loves a woman')


class CoreferenceEnglishMatchingTest(unittest.TestCase):
Example #3
0
import unittest
import holmes_extractor as holmes
import os
from holmes_extractor.tests.testing_utils import HolmesInstanceManager

script_directory = os.path.dirname(os.path.realpath(__file__))
ontology = holmes.Ontology(os.sep.join(
    (script_directory, 'test_ontology.owl')))
ontology_holmes_manager = HolmesInstanceManager(
    ontology).en_core_web_lg_ontology
symmetric_ontology = holmes.Ontology(os.sep.join(
    (script_directory, 'test_ontology.owl')),
                                     symmetric_matching=True)
symmetric_ontology_holmes_manager = holmes.Manager(model='en_core_web_lg',
                                                   ontology=symmetric_ontology)
no_ontology_coref_holmes_manager = holmes.Manager(model='en_coref_lg')


class EnglishPhraseletProductionTest(unittest.TestCase):
    def _check_equals(self,
                      manager,
                      text_to_match,
                      phraselet_labels,
                      replace_with_hypernym_ancestors=True,
                      match_all_words=False):
        manager.remove_all_search_phrases()
        doc = manager.semantic_analyzer.parse(text_to_match)
        manager.structural_matcher.register_phraselets(
            doc,
            replace_with_hypernym_ancestors=replace_with_hypernym_ancestors,
            match_all_words=match_all_words,
import holmes_extractor as holmes
import os

script_directory = os.path.dirname(os.path.realpath(__file__))
ontology = holmes.Ontology(
    os.sep.join(
        (script_directory, 'example_chatbot_DE_insurance_ontology.owl')))
holmes_manager = holmes.Manager(model='de_core_news_md', ontology=ontology)
holmes_manager.register_search_phrase('Jemand benötigt eine Versicherung')
holmes_manager.register_search_phrase(
    'Ein ENTITYPER schließt eine Versicherung ab')
holmes_manager.register_search_phrase('ENTITYPER benötigt eine Versicherung')
holmes_manager.register_search_phrase('Eine Versicherung für einen Zeitraum')
holmes_manager.register_search_phrase('Eine Versicherung fängt an')
holmes_manager.register_search_phrase('Jemand zahlt voraus')

holmes_manager.start_chatbot_mode_console()
import unittest
import holmes_extractor as holmes
import os

script_directory = os.path.dirname(os.path.realpath(__file__))
ontology = holmes.Ontology(os.sep.join(
    (script_directory, 'test_ontology.owl')))
symmetric_ontology = holmes.Ontology(os.sep.join(
    (script_directory, 'test_ontology.owl')),
                                     symmetric_matching=True)
combined_ontology_1 = holmes.Ontology([
    os.sep.join((script_directory, 'test_ontology.owl')),
    os.sep.join((script_directory, 'test_ontology2.owl'))
])
combined_ontology_2 = holmes.Ontology([
    os.sep.join((script_directory, 'test_ontology2.owl')),
    os.sep.join((script_directory, 'test_ontology.owl'))
])
combined_ontology_symmetric = holmes.Ontology([
    os.sep.join((script_directory, 'test_ontology.owl')),
    os.sep.join((script_directory, 'test_ontology2.owl'))
],
                                              symmetric_matching=True)


class OntologyTest(unittest.TestCase):
    def test_multiwords(self):
        self.assertTrue(ontology.contains_multiword('gymnastics equipment'))
        self.assertTrue(ontology.contains_multiword('German Shepherd dog'))
        self.assertTrue(ontology.contains_multiword('MIMI MOMO'))
        self.assertFalse(ontology.contains_multiword('horse'))
import urllib.request
import holmes_extractor as holmes
import re
import os
import json
import falcon

if __name__ in ('__main__', 'example_search_EN_literature'):

    script_directory = os.path.dirname(os.path.realpath(__file__))
    ontology = holmes.Ontology(
        os.sep.join(
            (script_directory, 'example_search_EN_literature_ontology.owl')))
    print('Initializing Holmes...')
    #Start the Holmes manager with the English model
    holmes_manager = holmes.MultiprocessingManager(
        model='en_core_web_lg',
        overall_similarity_threshold=0.9,
        ontology=ontology,
        number_of_workers=4)

    # set number_of_workers to prevent memory exhaustion / swapping; it should never be more
    # than the number of cores


    def extract_chapters_from_book(book_uri, title):
        """ Download and save the chapters from a book."""

        print()
        print(title)
        print()