Пример #1
0
def test_filter_invalid_ops():
    ops = [
        AdditionOperation(LiteralElement("a"),
                          URIElement("https://example.org"), None),
        RemovalOperation(LiteralElement("b"), None, LiteralElement("c")),
        AdditionOperation(LiteralElement("a"),
                          URIElement("https://example.org"), LiteralElement(2))
    ]
    filtered_ops = _filter_invalid_ops(ops)
    assert len(filtered_ops) == 1
    assert filtered_ops[0] == ops[2]
Пример #2
0
def test_optimize_ops(triple):
    triple_b = (URIElement('http://example.org/onto#Singer'),
                URIElement(RDFS_LABEL), LiteralElement('Cantante', 'es'))
    original_ops = [
        AdditionOperation(*triple),
        AdditionOperation(*triple_b),
        RemovalOperation(*triple)
    ]
    result_ops = optimize_ops(original_ops)
    assert len(result_ops) == 2
    for op in result_ops:
        assert isinstance(op, BatchOperation)
Пример #3
0
def test_str(triple):
    addition_op = AdditionOperation(*triple)
    assert str(
        addition_op
    ) == f"AdditionOperation: {triple[0]} - {triple[1]} - {triple[2]}"

    removal_op = RemovalOperation(*triple)
    assert str(
        removal_op
    ) == f"RemovalOperation: {triple[0]} - {triple[1]} - {triple[2]}"

    batch_op = BatchOperation(triple[0], [triple, triple])
    assert str(batch_op) == f"BatchOperation: {triple[0]}\n{triple}\n{triple}"
Пример #4
0
    def test_basic(self, algorithm, input):
        operations = algorithm.do_algorithm(input[0], input[1])

        administrative_personnel = EX_PREFIX + 'AdministrativePersonnel'
        changed_personnel = EX_PREFIX + 'ChangedPersonnel'
        human_resource = ASIO_PREFIX + 'HumanResource'
        research_personnel = EX_PREFIX + 'ResearchPersonnel'
        technical_personnel = ASIO_PREFIX + 'TechnicalPersonnel'

        addition_ops = [
            AdditionOperation(URIElement(administrative_personnel),
                              URIElement(OWL_DISJOINT_WITH),
                              URIElement(changed_personnel)),
            AdditionOperation(URIElement(changed_personnel),
                              URIElement(RDF_TYPE), URIElement(OWL_CLASS)),
            AdditionOperation(URIElement(technical_personnel),
                              URIElement(RDF_TYPE), URIElement(OWL_CLASS)),
            AdditionOperation(URIElement(technical_personnel),
                              URIElement(RDFS_SUBCLASSOF),
                              URIElement(human_resource)),
            AdditionOperation(
                URIElement(technical_personnel), URIElement(RDFS_COMMENT),
                LiteralElement('Personnel devoted to technical suport.',
                               lang='en')),
            AdditionOperation(URIElement(technical_personnel),
                              URIElement(RDFS_LABEL),
                              LiteralElement('Personal tècnic', lang='ca-ad')),
            AdditionOperation(URIElement(technical_personnel),
                              URIElement(RDFS_LABEL),
                              LiteralElement('Personal tècnic', lang='ca-es')),
            AdditionOperation(URIElement(technical_personnel),
                              URIElement(RDFS_LABEL),
                              LiteralElement('Personal técnico', lang='es')),
            AdditionOperation(URIElement(technical_personnel),
                              URIElement(RDFS_LABEL),
                              LiteralElement('Personnel technique',
                                             lang='fr')),
            AdditionOperation(URIElement(technical_personnel),
                              URIElement(RDFS_LABEL),
                              LiteralElement('Pessoal técnico', lang='pt')),
            AdditionOperation(URIElement(technical_personnel),
                              URIElement(RDFS_LABEL),
                              LiteralElement(12, datatype=XSD.integer)),
            AdditionOperation(URIElement(technical_personnel),
                              URIElement(RDFS_LABEL),
                              LiteralElement('Technical personnel', lang='en'))
        ]
        removal_ops = [
            RemovalOperation(URIElement(administrative_personnel),
                             URIElement(OWL_DISJOINT_WITH),
                             URIElement(research_personnel)),
            RemovalOperation(URIElement(research_personnel),
                             URIElement(RDF_TYPE), URIElement(OWL_CLASS)),
            RemovalOperation(URIElement(research_personnel),
                             URIElement(RDFS_SUBCLASSOF),
                             URIElement(EX_PREFIX + 'HumanResource'))
        ]
        expected = addition_ops + removal_ops

        assert len(operations) == len(expected)

        for op in operations:
            triple = op._triple_info
            if isinstance(op, AdditionOperation):
                assert triple.isAdded
            elif isinstance(op, RemovalOperation):
                assert not triple.isAdded
            else:
                assert False, "Invalid operation type detected"
Пример #5
0
def _generate_test_ops():
    return [AdditionOperation(None, None, None), 
            AdditionOperation(None, None, None),
            RemovalOperation(None, None, None)]
Пример #6
0
def test_two_operations_with_same_triple_are_distinct(triple):
    add = AdditionOperation(*triple)
    remove = RemovalOperation(*triple)
    assert add != remove
Пример #7
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))
Пример #8
0
def test_init(triple):
    addition_op = AdditionOperation(*triple)
    assert addition_op._triple_info == TripleInfo(*triple)