def test_uri_etype(): element = URIElement('') assert element.etype == 'item' element.etype = 'property' assert element.etype == 'property' with pytest.raises(InvalidArgumentError) as excpt: element.etype = 'invented' assert 'Invalid etype' in str(excpt.value)
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]
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)
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"
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')) }
def item_uri(): uri = 'http://example.org/onto#Person' return URIElement(uri)
def prop_uri(): uri = 'http://example.org/onto#livesIn' etype = 'property' return URIElement(uri, etype)
def triple(): subject = URIElement('http://example.org/onto#Person') predicate = URIElement(RDFS_LABEL) objct = LiteralElement('Persona', 'es') return (subject, predicate, objct)