예제 #1
0
    def test_load_from_graph_ContextHashBasedString(self):
        context = NIFContext(
            uri=
            'http://freme-project.eu#hash_0_33_cf35b7e267d05b7ca8aba0651641050b_Diego%20Maradona%20is%20fr',
            mention="Diego Maradona is from Argentina.",
            is_hash_based_uri=True)
        context.add_phrase(
            uri=
            'http://freme-project.eu#hash_19_33_158118325b076b079d3969108872d855_Diego%20Maradona%20is%20fr',
            is_hash_based_uri=True,
            beginIndex=0,
            endIndex=14,
            score=0.9869992701528016,
            taClassRef=[
                'http://dbpedia.org/ontology/SportsManager',
                'http://dbpedia.org/ontology/Person',
                'http://nerd.eurecom.fr/ontology#Person'
            ],
            annotator='http://freme-project.eu/tools/freme-ner',
            taIdentRef='http://dbpedia.org/resource/Diego_Maradona',
            taMsClassRef='http://dbpedia.org/ontology/SoccerManager')
        g = Graph().parse(format='turtle',
                          data=self.example_ContextHashBasedString)
        uri = URIRef(
            'http://freme-project.eu#hash_0_33_cf35b7e267d05b7ca8aba0651641050b_Diego%20Maradona%20is%20fr'
        )
        parsed_context = NIFContext.load_from_graph(g, uri)

        self.assertTrue(turtle_equal(context.turtle, parsed_context.turtle))
예제 #2
0
    def test_create_populated_ContextHashBasedString(self):
        context = NIFContext(
            uri=
            'http://freme-project.eu#hash_0_33_cf35b7e267d05b7ca8aba0651641050b_Diego%20Maradona%20is%20fr',
            mention="Diego Maradona is from Argentina.",
            is_hash_based_uri=True)
        context.add_phrase(
            uri=
            'http://freme-project.eu#hash_19_33_158118325b076b079d3969108872d855_Diego%20Maradona%20is%20fr',
            is_hash_based_uri=True,
            beginIndex=0,
            endIndex=14,
            score=0.9869992701528016,
            taClassRef=[
                'http://dbpedia.org/ontology/SportsManager',
                'http://dbpedia.org/ontology/Person',
                'http://nerd.eurecom.fr/ontology#Person'
            ],
            annotator='http://freme-project.eu/tools/freme-ner',
            taIdentRef='http://dbpedia.org/resource/Diego_Maradona',
            taMsClassRef='http://dbpedia.org/ontology/SoccerManager')

        self.assertEqual(0, context.phrases[0].beginIndex)
        self.assertEqual(14, context.phrases[0].endIndex)
        self.assertEqual("Diego Maradona", context.phrases[0].mention)
        self.assertEqual(0.9869992701528016, context.phrases[0].score)
        self.assertTrue(
            turtle_equal(context.turtle, self.example_ContextHashBasedString))
예제 #3
0
    def test_add_phrase(self):
        c = NIFContext(
            uri=
            'http://www.cse.iitb.ac.in/~soumen/doc/CSAW/doc/yn_08Oct08_file_0',
            mention=self.example_text)

        b = c.add_phrase(91, 102)
        self.assertEqual(91, b.beginIndex)
        self.assertEqual(102, b.endIndex)
        self.assertEqual("Afghanistan", b.mention)
        self.assertEqual(
            "http://www.cse.iitb.ac.in/~soumen/doc/CSAW/doc/yn_08Oct08_file_0",
            b.context)
예제 #4
0
    def test_turtle(self):
        c = NIFContext(
            uri=
            'http://www.cse.iitb.ac.in/~soumen/doc/CSAW/doc/yn_08Oct08_file_0/#offset_0_1411',
            mention=self.example_text)

        self.assertTrue(turtle_equal(self.example_turtle, c.turtle))
예제 #5
0
    def test_load_from_graph(self):
        g = Graph().parse(format='turtle', data=self.example_turtle)
        uri = URIRef(
            'http://www.cse.iitb.ac.in/~soumen/doc/CSAW/doc/yn_08Oct08_file_0/#offset_0_1411'
        )
        context = NIFContext.load_from_graph(g, uri)

        self.assertEqual(self.example_text, context.mention)
        self.assertEqual(0, context.beginIndex)
        self.assertEqual(len(self.example_text), context.endIndex)
예제 #6
0
    def test_create_ContextHashBasedString_context(self):
        context = NIFContext(
            uri=
            'http://www.cse.iitb.ac.in/~soumen/doc/CSAW/doc#hash_0_1411_6218664a3a8c7bed58460e329ddc6904_%20%20%20%20Primary%20Navigati',
            mention=self.example_text,
            is_hash_based_uri=True)

        self.assertEqual(self.example_text, context.mention)
        self.assertEqual(0, context.beginIndex)
        self.assertEqual(1411, context.endIndex)
        self.assertTrue(
            turtle_equal(self.example_turtle_ContextHashBasedString,
                         context.turtle))
예제 #7
0
    def test_load_ContextHashBasedString(self):
        g = Graph().parse(format='turtle',
                          data=self.example_ContextHashBasedString)
        uri = URIRef(
            'http://freme-project.eu#hash_0_33_cf35b7e267d05b7ca8aba0651641050b_Diego%20Maradona%20is%20fr'
        )
        parsed_context = NIFContext.load_from_graph(g, uri)

        self.assertTrue(parsed_context.isContextHashBasedString)
        for phrase in parsed_context.phrases:
            self.assertTrue(phrase.isContextHashBasedString)
        self.assertTrue(
            turtle_equal(parsed_context.turtle,
                         self.example_ContextHashBasedString))
예제 #8
0
 def test_to_string(self):
     c = NIFContext()
     c.baseURI = 'http://www.cse.iitb.ac.in/~soumen/doc/CSAW/doc/yn_08Oct08_file_0/'
     c.beginIndex = 0
     c.mention = "    Primary Navigation Secondary Navigation Search: Nearly 60 militants killed"
     c.endIndex = len(c.mention)
     self.assertEqual(
         "<NIFContext 0-78: '    Primary Navigation Secondary Navigation Search...'>",
         str(c))
예제 #9
0
 def test_original_uri(self):
     b = NIFContext()
     b.original_uri = 'http://example.com/my_annotation'
     self.assertEqual('http://example.com/my_annotation', str(b.uri))
예제 #10
0
 def test_to_string_undefined(self):
     c = NIFContext()
     self.assertEqual("<NIFContext (undefined)>", str(c))