def test_collection_to_rdf_should_return_skos_collection():
    with open('./tests/collection.json') as json_file:
        data = json.load(json_file)
        _collection = data['collection']

    # Create the collection:
    collection = Collection()
    collection.identifier = _collection['identifier']
    collection.name = _collection['name']
    collection.description = _collection['description']
    collection.publisher = _collection['publisher']
    collection.contactpoint = Contact(_collection['contactpoint'])

    # Add members:
    collection.members = []
    for concept in _collection['members']:
        collection.members.append(Concept(concept))

    # Get the collection as rdf:
    data = collection.to_rdf()

    # Test
    g1 = Graph()
    g1.parse(data=data, format='turtle')
    # _dump_turtle(g1)
    g2 = Graph().parse("tests/collection.ttl",
                       format='turtle', encoding='utf-8')

    _isomorphic = isomorphic(g1, g2)
    if not _isomorphic:
        _dump_diff(g1, g2)
        pass
    assert _isomorphic
Beispiel #2
0
def test_quoteFromSource_to_rdf_should_return_skos_definition():

    with open('./tests/definition.json') as json_file:
        data = json.load(json_file)
        _definition = data['definition']
    definition = Definition()
    definition.identifier = _definition['identifier']
    definition.relationtosource = 'quoteFromSource'
    definition.source = _definition['source']

    concept = Concept()
    concept.identifier = 'http://example.com/concepts/1'
    concept.definition = definition

    g1 = Graph()
    g1.parse(data=concept.to_rdf(), format='turtle')
    # _dump_turtle(g1)
    # -
    src = '''
    @prefix dct: <http://purl.org/dc/terms/> .
    @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
    @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
    @prefix skos: <http://www.w3.org/2004/02/skos/core#> .
    @prefix skosno: <http://difi.no/skosno#> .
    @prefix xml: <http://www.w3.org/XML/1998/namespace> .
    @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

    <http://example.com/concepts/1> a skos:Concept ;
            skosno:betydningsbeskrivelse [ a skosno:Definisjon ;
            skosno:forholdTilKilde skosno:sitatFraKilde ;
            dct:source [ rdfs:label "Thrustworthy source"@en,
                "Stolbar kilde"@nb,
                "Stolbar kilde"@nn ;
                rdfs:seeAlso <http://www.example.com/trustworthysources/1> ]
                ] .
    '''
    # -
    g2 = Graph().parse(data=src, format='turtle', encoding='utf-8')

    _isomorphic = isomorphic(g1, g2)
    if not _isomorphic:
        _dump_diff(g1, g2)
        pass
    assert _isomorphic
Beispiel #3
0
def test_simple_concept_to_rdf_should_return_skos_concept():
    with open('./tests/concept.json') as json_file:
        data = json.load(json_file)
        _concept = data['concept']
    concept = Concept()
    concept.identifier = _concept['identifier']
    concept.term = _concept['term']
    concept.definition = Definition(_concept['definition'])
    concept.alternativformulering = AlternativFormulering(
        _concept['alternativformulering'])
    concept.publisher = _concept['publisher']
    concept.contactpoint = Contact(_concept['contactpoint'])

    g1 = Graph()
    g1.parse(data=concept.to_rdf(), format='turtle')
    # _dump_turtle(g1)
    g2 = Graph().parse("tests/concept.ttl", format='turtle', encoding='utf-8')

    _isomorphic = isomorphic(g1, g2)
    if not _isomorphic:
        # _dump_diff(g1, g2)
        pass
    assert _isomorphic
Beispiel #4
0
def test_concept_to_rdf_should_return_skos_concept():
    with open('./tests/completeconcept.json') as json_file:
        data = json.load(json_file)
        _concept = data['concept']
    concept = Concept()
    concept.identifier = _concept['identifier']
    concept.term = _concept['term']
    concept.alternativeterm = _concept['alternativeterm']
    concept.hiddenterm = _concept['hiddenterm']
    concept.definition = Definition(_concept['definition'])
    concept.alternativformulering = AlternativFormulering(
        _concept['alternativformulering'])
    concept.publisher = _concept['publisher']
    concept.contactpoint = Contact(_concept['contactpoint'])
    concept.subject = _concept['subject']
    concept.modified = _concept['modified']
    concept.example = _concept['example']
    concept.bruksområde = _concept['bruksområde']
    concept.validinperiod = _concept['validinperiod']
    concept.modified = _concept['modified']
    # --
    concept.related = AssociativeRelation(_concept['related'])
    for ac in _concept['related']['associatedconcepts']:
        concept.related.associatedconcepts.append(ac)
    # --
    concept.generalizes = GenericRelation(_concept['generalizes'])
    for gc in _concept['generalizes']['genericconcepts']:
        concept.generalizes.genericconcepts.append(gc)
    # --
    concept.hasPart = PartitiveRelation(_concept['hasPart'])
    for pc in _concept['hasPart']['partconcepts']:
        concept.hasPart.partconcepts.append(pc)
    # --
    for c in _concept['seeAlso']:
        seeAlsoConcept = Concept()
        seeAlsoConcept.identifier = c
        concept.seeAlso.append(seeAlsoConcept)
    # --
    for c in _concept['replaces']:
        replacesConcept = Concept()
        replacesConcept.identifier = c
        concept.replaces.append(replacesConcept)
    # --
    for c in _concept['replacedBy']:
        replacedByConcept = Concept()
        replacedByConcept.identifier = c
        concept.replacedBy.append(replacedByConcept)
    # --

    g1 = Graph()
    g1.parse(data=concept.to_rdf(), format='turtle')
    _dump_turtle(g1)
    g2 = Graph().parse("tests/completeconcept.ttl",
                       format='turtle',
                       encoding='utf-8')

    _isomorphic = isomorphic(g1, g2)
    if not _isomorphic:
        _dump_diff(g1, g2)
        pass
    assert _isomorphic
Beispiel #5
0
def test_concept_constructor_to_rdf_should_return_skos_concept():
    with open('./tests/completeconcept.json') as json_file:
        data = json.load(json_file)
        _concept = data['concept']
    concept = Concept(_concept)
    # --
    concept.related = AssociativeRelation(_concept['related'])
    for ac in _concept['related']['associatedconcepts']:
        concept.related.associatedconcepts.append(ac)
    # --
    concept.generalizes = GenericRelation(_concept['generalizes'])
    for gc in _concept['generalizes']['genericconcepts']:
        concept.generalizes.genericconcepts.append(gc)
    # --
    concept.hasPart = PartitiveRelation(_concept['hasPart'])
    for pc in _concept['hasPart']['partconcepts']:
        concept.hasPart.partconcepts.append(pc)
    # --
    # --
    for c in _concept['seeAlso']:
        seeAlsoConcept = Concept()
        seeAlsoConcept.identifier = c
        concept.seeAlso.append(seeAlsoConcept)
    # --
    for c in _concept['replaces']:
        replacesConcept = Concept()
        replacesConcept.identifier = c
        concept.replaces.append(replacesConcept)
    # --
    for c in _concept['replacedBy']:
        replacedByConcept = Concept()
        replacedByConcept.identifier = c
        concept.replacedBy.append(replacedByConcept)

    g1 = Graph()
    g1.parse(data=concept.to_rdf(), format='turtle')
    # _dump_turtle(g1)
    g2 = Graph().parse("tests/completeconcept.ttl",
                       format='turtle',
                       encoding='utf-8')

    _isomorphic = isomorphic(g1, g2)
    if not _isomorphic:
        # _dump_diff(g1, g2)
        pass
    assert _isomorphic
Beispiel #6
0
from concepttordf.concept import Concept
from concepttordf.definition import Definition

# create a concept
concept = Concept()
# set identifier
concept.identifier = "http://example.com/concepts/1"
# set term
concept.term = {"name": {"nb": "begrep", "en": "concept"}}
# set definition
definition = Definition()
definition.text = {
    "nb": ("mental forestilling om et konkret eller abstrakt"
           "fenomen i den virkelige verden"),
    "en": ("an abstract or generic idea generalized from"
           "particular instances")
}
concept.definition = definition
# set publisher
concept.publisher = "https://example.com/publishers/1"

# get rdf representation in turtle (default)
rdf = concept.to_rdf()
print(rdf.decode())

# get rdf representation in xml
rdf = concept.to_rdf(format='xml')
print(rdf.decode())