Beispiel #1
0
def test_thing_wikidata_query_strict_True():
    """Thing - wikidata - strict=True - : Should pass """
    thing = Thing()
    thing.add_query_endpoint(Endpoint.wikidata)
    thing.query(strict_mode=True)

    assert thing.endpoints == set([Endpoint.wikidata])
    assert thing.query_language == Lang.English

    expected_query = """
   PREFIX owl: <http://www.w3.org/2002/07/owl#>
   PREFIX wd: <http://www.wikidata.org/entity/>
   PREFIX schema: <http://schema.org/>
   PREFIX dbo: <http://dbpedia.org/ontology/>
   PREFIX wdt_o: <http://www.wikidata.org/ontology#>
   SELECT DISTINCT ?Thing ?pred ?obj WHERE {
   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
   ?Thing ?pred ?obj .
   { ?Thing a owl:Class  } UNION
   { ?Thing a schema:Class  } UNION
   { ?Thing a wd:Q35120  } UNION
   { ?Thing a schema:Thing  } UNION
   { ?Thing a wdt_o:Item  } UNION
   { ?Thing a dbo:Thing  } UNION
   { ?Thing a owl:Thing  } .
   } LIMIT 1500
   """
    ratio = fuzz.token_sort_ratio(
        thing.query_builder.queries[Endpoint.wikidata], expected_query)
    assert ratio > 90
Beispiel #2
0
def test_thing_dbpedia_fr_query_strict_True():
    """Thing - dbpedia_fr - strict=True - : Should pass """
    label = "Acide pinique"
    thing = Thing(label=label, query_language=Lang.French)
    thing.add_query_endpoint(Endpoint.dbpedia_fr)
    thing.query(strict_mode=True)

    assert thing.endpoints == set([Endpoint.dbpedia_fr])
    assert thing.has_label == u'Acide pinique'
    assert thing.query_language == Lang.French
    assert thing.attributes
    assert thing.labels_by_languages
Beispiel #3
0
def test_thing_dbpedia_fr_query_strict_False():
    """Thing - dbpedia_fr - strict=False - : Should pass """

    label = u"11e régiment du génie"
    thing = Thing(label=label, query_language=Lang.French)
    thing.add_query_endpoint(Endpoint.dbpedia_fr)
    thing.query(strict_mode=False)

    assert thing.endpoints == set([Endpoint.dbpedia_fr])
    assert thing.has_label == u'11e r\xe9giment du g\xe9nie'
    assert thing.query_language == Lang.French
    assert thing.labels_by_languages
    assert thing.attributes
Beispiel #4
0
def test_thing_dbpedia_query_strict_False():
    """Thing - dbpedia - strict=False - : Should pass """
    thing = Thing(label=u"Paris", query_language=Lang.French, limit=666)
    thing.add_query_endpoint(Endpoint.dbpedia)
    thing.query(strict_mode=False)

    expected = {
        'endpoints': set([Endpoint.dbpedia]),
        'has_label': u"Paris",
        'query_language': Lang.French,
    }
    assert thing.endpoints == expected.get('endpoints')
    assert thing.has_label == expected.get('has_label')
    assert thing.query_language == expected.get('query_language')
    assert thing.attributes
    assert thing.labels_by_languages
Beispiel #5
0
def test_thing_dbpedia_query_strict_True():
    """Thing - dbpedia - strict=True - : Should pass"""
    thing = Thing(label=u'አዲስ አበባ', query_language=Lang.Amharic)
    thing.add_query_endpoint(Endpoint.dbpedia)
    thing.query(strict_mode=True)

    expected = {
        'args': {
            'object': u'?obj',
            'predicate': u'?pred',
            'subject': u'?Thing'
        },
        'class_name': u'Thing',
        'endpoints': set([Endpoint.dbpedia]),
        'has_label': u'\u12a0\u12f2\u1235 \u12a0\u1260\u1263',
        'query_language': Lang.Amharic,
    }
    assert thing.args == expected.get('args')
    assert thing.class_name == expected.get('class_name')
    assert thing.endpoints == expected.get('endpoints')
    assert thing.has_label == expected.get('has_label')
    assert thing.query_language == expected.get('query_language')
    assert thing.attributes
Beispiel #6
0
def test_thing_wikidata_query_strict_False():
    """Thing - wikidata - strict=True, check_type=False - : Should pass"""
    thing = Thing(label=u"혁kστ혁ηjh혁kي혁ةsjdジアh", query_language=Lang.DEFAULT)
    thing.add_query_endpoint(Endpoint.wikidata)
    thing.query(strict_mode=True, check_type=False)

    assert thing.endpoints == set([Endpoint.wikidata])
    assert thing.has_label == u'혁kστ혁ηjh혁kي혁ةsjdジアh'
    assert thing.query_language == Lang.English

    expected_query = u'''
   PREFIX wdt: <http://www.wikidata.org/prop/direct/>
   PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
   SELECT DISTINCT ?Thing ?pred ?obj WHERE
   { SERVICE wikibase:label
    { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
     ?Thing ?pred ?obj .
     { ?Thing rdfs:label "혁kστ혁ηjh혁kي혁ةsjdジアh"@en  }
     UNION { ?Thing wdt:P1813 "혁kστ혁ηjh혁kي혁ةsjdジアh"@en  } .
       } LIMIT 1500'''

    ratio = fuzz.token_sort_ratio(
        thing.query_builder.queries[Endpoint.wikidata], expected_query)
    assert ratio > 90
Beispiel #7
0
def test_thing_bnf_query_strict_False():
    """Thing - bnf - strict=False - : Should pass """
    thing = Thing(label="Nothing", query_language=Lang.English)
    thing.add_query_endpoint(Endpoint.bnf)
    thing.query(strict_mode=False)
    assert thing.attributes.get(u'owl:complementOf') == u'owl:Thing'
Beispiel #8
0
def test_thing_bnf_query_strict_True():
    """Thing - bnf - strict=True - : Should pass """
    thing = Thing(label="Thing", query_language=Lang.English)
    thing.add_query_endpoint(Endpoint.bnf)
    thing.query(strict_mode=True)
    assert thing.attributes.get(u'owl:sameAs') == u'owl:Thing'