Exemplo n.º 1
0
def test_from_rdflib(rdflib_triple):
    triple = TripleInfo.from_rdflib(rdflib_triple).content
    assert isinstance(triple[0], URIElement)
    assert isinstance(triple[1], URIElement)
    assert isinstance(triple[2], LiteralElement)

    assert triple[0].uri == str(rdflib_triple[0])
    assert triple[1].uri == str(rdflib_triple[1])
    assert triple[2].content == rdflib_triple[2].value
    assert triple[2].datatype is None
    assert triple[2].lang is None

    assert triple != str(rdflib_triple)

    bnode = TripleElement.from_rdflib(BNode('cb0'))
    assert isinstance(bnode, AnonymousElement)
    assert bnode.uid == 'cb0'
    assert bnode == f'{ASIO_BASE}/genid/cb0'
Exemplo n.º 2
0
 def _create_remove_ops_from(self, graph: Graph) -> List[RemovalOperation]:
     return [
         RemovalOperation(*TripleInfo.from_rdflib(triple).content)
         for triple in graph
     ]
Exemplo n.º 3
0
 def _create_add_ops_from(self, graph: Graph) -> List[AdditionOperation]:
     return [
         AdditionOperation(*TripleInfo.from_rdflib(triple).content)
         for triple in graph
     ]
Exemplo n.º 4
0
def triples():
    example = 'https://example.org/onto#'
    example_no_hashtag = 'https://example.org/onto/'
    example_no_label = 'example'
    example_asio = 'https://example.org/hercules/asio#'

    return {
        'alias_en':
        TripleInfo(URIElement(example + 'Person'), URIElement(SKOS_ALTLABEL),
                   LiteralElement('individual', lang='en')),
        'alias_es':
        TripleInfo(URIElement(example + 'Person'), URIElement(SKOS_ALTLABEL),
                   LiteralElement('individuo', lang='es')),
        'alias_es_2':
        TripleInfo(URIElement(example + 'Person'), URIElement(SKOS_ALTLABEL),
                   LiteralElement('sujeto', lang='es')),
        'anonymous_element':
        TripleInfo(
            URIElement(example + 'test',
                       etype='property',
                       proptype=f"{ASIO_BASE}property"),
            URIElement(example + 'livesIn'), AnonymousElement('cb013')),
        'desc_en':
        TripleInfo(URIElement(example + 'Person'), URIElement(RDFS_COMMENT),
                   LiteralElement('A person', lang='en')),
        'desc_es':
        TripleInfo(URIElement(example + 'Person'), URIElement(RDFS_COMMENT),
                   LiteralElement('Una persona', lang='es')),
        'desc_long':
        TripleInfo(URIElement(example + 'Person'), URIElement(RDFS_COMMENT),
                   LiteralElement('Una persona' * 500, lang='es')),
        'desc_asio':
        TripleInfo(
            URIElement(example_asio + 'authors'), URIElement(RDFS_COMMENT),
            LiteralElement('Publication authored by a person.', lang='en')),
        'label_en':
        TripleInfo(URIElement(example + 'labra'), URIElement(RDFS_LABEL),
                   LiteralElement('Jose Emilio Labra Gayo', lang='en')),
        'label_ko':
        TripleInfo(URIElement(example + 'labra'), URIElement(RDFS_LABEL),
                   LiteralElement('라브라', lang='ko')),
        'label_no_lang':
        TripleInfo(URIElement(example + 'labra'), URIElement(RDFS_LABEL),
                   LiteralElement('José Emilio Labra Gayo')),
        'label_unknown':
        TripleInfo(URIElement(example + 'labra'), URIElement(RDFS_LABEL),
                   LiteralElement('라브', lang='invented')),
        'literal_datatype':
        TripleInfo(
            URIElement(example + 'Person'), URIElement(example + 'livesIn'),
            LiteralElement('Point(12.34 2.43)',
                           datatype=f"{GEO_BASE}wktLiteral")),
        'no_label':
        TripleInfo(URIElement(example_no_label + 'test'),
                   URIElement(RDFS_LABEL), LiteralElement('a test',
                                                          lang='en')),
        'no_hashtag':
        TripleInfo(URIElement(example_no_hashtag + 'test'),
                   URIElement(RDFS_LABEL), LiteralElement('1234', lang='en')),
        'proptype':
        TripleInfo(
            URIElement(example + 'test',
                       etype='property',
                       proptype=f"{ASIO_BASE}property"),
            URIElement(RDFS_LABEL), LiteralElement('test')),
        'wditemid':
        TripleInfo(URIElement(example + 'Person'),
                   URIElement(example + 'livesIn'),
                   URIElement(example + 'City')),
        'wdstring':
        TripleInfo(URIElement(example + 'Person'),
                   URIElement(example + 'altName'), LiteralElement('Human'))
    }
Exemplo n.º 5
0
def test_is_added(rdflib_triple):
    triple = TripleInfo.from_rdflib(rdflib_triple)
    assert triple.isAdded

    triple_to_delete = TripleInfo.from_rdflib(rdflib_triple, isAdded=False)
    assert not triple_to_delete.isAdded
Exemplo n.º 6
0
def test_tripleinfo_str(rdflib_triple):
    triple = TripleInfo.from_rdflib(rdflib_triple)
    assert str(
        triple) == f"{triple.subject} - {triple.predicate} - {triple.object}"
Exemplo n.º 7
0
def test_removal(mock_triplestore, triple):
    removal_op = RemovalOperation(*triple)
    removal_op.execute(mock_triplestore)
    mock_triplestore.remove_triple.assert_called_once_with(TripleInfo(*triple))
Exemplo n.º 8
0
def test_addition(mock_triplestore, triple):
    addition_op = AdditionOperation(*triple)
    addition_op.execute(mock_triplestore)
    mock_triplestore.create_triple.assert_called_once_with(TripleInfo(*triple))
Exemplo n.º 9
0
def test_init(triple):
    addition_op = AdditionOperation(*triple)
    assert addition_op._triple_info == TripleInfo(*triple)