コード例 #1
0
    def test_add_rdf_file(self):
        """ Test adding RDF directly from a file """
        filename = os.path.join(os.path.dirname(__file__), '..', 'data', 'earl_report.ttl')
        pl = PrefixLibrary()
        self.assertEqual("""PREFIX xml: <http://www.w3.org/XML/1998/namespace>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX dc: <http://purl.org/dc/terms/>
PREFIX doap: <http://usefulinc.com/ns/doap#>
PREFIX earl: <http://www.w3.org/ns/earl#>
PREFIX ex: <http://example.org/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX ns1: <http://purl.org/dc/elements/1.1/>""", str(pl.add_rdf(filename)).strip())
        g = Graph()
        g.load(filename, format="turtle")
        pl = PrefixLibrary()
        self.assertEqual("""PREFIX xml: <http://www.w3.org/XML/1998/namespace>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX dc: <http://purl.org/dc/terms/>
PREFIX doap: <http://usefulinc.com/ns/doap#>
PREFIX earl: <http://www.w3.org/ns/earl#>
PREFIX ex: <http://example.org/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX ns1: <http://purl.org/dc/elements/1.1/>""", str(pl.add_rdf(g)).strip())
コード例 #2
0
    def test_mappings_rdf(self):
        """ Test the imported mappings in the biolink metamodel """

        # Generate context and use it to create the RDF
        self.single_file_generator('jsonld', ContextGenerator, filtr=ldcontext_metadata_filter)

        # Generate a copy of the JSON representation of the model
        context_loc = os.path.join(self.source_path, self.model_name + ".jsonld")
        context_args = {"context": [LOCAL_METAMODEL_LDCONTEXT_FILE, context_loc]}
        self.single_file_generator('json', JSONLDGenerator,  serialize_args=context_args,  filtr=json_metadata_filter)

        # Make a fresh copy of the RDF and validate it as well
        self.single_file_generator('ttl', RDFGenerator, serialize_args=context_args,
                                   comparator=GeneratorTestCase.rdf_comparator)

        g = Graph()
        rdf_file = os.path.join(sourcedir, 'meta_mappings.ttl')
        g.load(rdf_file, format='turtle')
        ns = PrefixLibrary()
        ns.add_rdf(g)
        ns['FULL'] = "http://example.org/fulluri/"
        ns['EX'] = "http://example.org/mappings/"
        ns['META'] = "https://w3id.org/biolink/biolinkml/meta/"
        # Make sure that the expected triples got added

        self.assertEqual({ns.EX.slot1_close, ns.FULL.slot1_close}, set(g.objects(ns.EX.s1, ns.SKOS.closeMatch)))
        self.assertEqual({ns.EX.slot1, ns.FULL.slot1}, set(g.objects(ns.EX.s1, ns.SKOS.exactMatch)))
        self.assertEqual(ns.EX.s3, g.value(ns.EX.s1, ns.META.deprecated_element_has_exact_replacement, any=False))
        self.assertEqual(ns.EX.s4, g.value(ns.EX.s1, ns.META.deprecated_element_has_possible_replacement, any=False))

        self.assertEqual({ns.EX.class1_close, ns.FULL.class1_close}, set(g.objects(ns.EX.C1, ns.SKOS.closeMatch)))
        self.assertEqual({ns.EX.class1, ns.FULL.class1}, set(g.objects(ns.EX.C1, ns.SKOS.exactMatch)))
        self.assertEqual(ns.EX.c2, g.value(ns.EX.C1, ns.META.deprecated_element_has_exact_replacement, any=False))
        self.assertEqual(ns.EX.c3, g.value(ns.EX.C1, ns.META.deprecated_element_has_possible_replacement, any=False))
        if DO_SHEX_VALIDATION:
            EX = Namespace("http://example.org/mappings/")
            focus = EX.testMetamodelMappings
            start = METAMODEL_NAMESPACE.SchemaDefinition
            results = ShExEvaluator(g, LOCAL_SHEXJ_FILE_NAME, focus, start).evaluate(debug=False)
            self.assertTrue(self._evaluate_shex_results(results))
        else:
            print("*** RDF Model validation step was skipped. Set: tests.__init__.DO_SHEX_VALIDATION to run it")
コード例 #3
0
    def test_add_rdf_str(self):
        """ Test adding RDF directly from a string """
        pl = PrefixLibrary()

        rdf = """
@prefix dc: <http://purl.org/dc/elements/1.1/> .
@prefix dcterms: <http://purl.org/dc/terms/> .
@prefix doap: <http://usefulinc.com/ns/doap#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix ex: <http://example.org/test/> .

ex:Sam a foaf:Person."""
        pl.add_rdf(rdf)
        self.assertEqual("""PREFIX xml: <http://www.w3.org/XML/1998/namespace>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX doap: <http://usefulinc.com/ns/doap#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX ex: <http://example.org/test/>""", str(pl).strip())
コード例 #4
0
    def test_add_rdf_url(self):
        """ Test adding RDF from a URL """
        pl = PrefixLibrary()
        pl.add_rdf("https://raw.githubusercontent.com/prefixcommons/biocontext/master/registry/go_context.jsonld",
                   format="json-ld")
        self.assertEqual("""PREFIX xml: <http://www.w3.org/XML/1998/namespace>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX wb: <http://identifiers.org/wormbase/>
PREFIX kegg_ligand: <http://www.genome.jp/dbget-bin/www_bget?cpd:>
PREFIX pso_git: <https://github.com/Planteome/plant-stress-ontology/issues/>
PREFIX ncbigene: <http://identifiers.org/ncbigene/>
PREFIX kegg_reaction: <http://www.genome.jp/dbget-bin/www_bget?rn:>
PREFIX go_ref: <http://purl.obolibrary.org/obo/go/references/>
PREFIX vega: <http://vega.sanger.ac.uk/id/>
PREFIX zfin: <http://identifiers.org/zfin/>
PREFIX pfam: <http://pfam.xfam.org/family/>
PREFIX sgn: <http://identifiers.org/sgn/>
PREFIX reactome: <http://identifiers.org/reactome/>
PREFIX interpro: <http://identifiers.org/interpro/>
PREFIX unirule: <http://www.uniprot.org/unirule/>
PREFIX dictybase: <http://identifiers.org/dictybase.gene/>
PREFIX po_git: <https://github.com/Planteome/plant-ontology/issues/>
PREFIX aspgd_locus: <http://identifiers.org/aspgd.locus/>
PREFIX sgd: <http://identifiers.org/sgd/>
PREFIX hgnc: <http://identifiers.org/hgnc/>
PREFIX dictybase_gene_name: <http://dictybase.org/gene/>
PREFIX tair: <http://identifiers.org/tair.locus/>
PREFIX ensemblfungi: <http://www.ensemblgenomes.org/id/>
PREFIX wikipedia: <http://en.wikipedia.org/wiki/>
PREFIX psi-mod: <http://www.ebi.ac.uk/ontology-lookup/?termId=MOD:>
PREFIX rgd: <http://identifiers.org/rgd/>
PREFIX pmid: <http://www.ncbi.nlm.nih.gov/pubmed/>
PREFIX xenbase: <http://identifiers.org/xenbase/>
PREFIX maizegdb: <http://maizegdb.org/gene_center/gene/>
PREFIX hamap: <http://hamap.expasy.org/unirule/>
PREFIX to_git: <https://github.com/Planteome/plant-trait-ontology/issues/>
PREFIX mesh: <http://n2t.net/MESH:>
PREFIX gr_protein: <http://identifiers.org/gramene.protein/>
PREFIX pombase: <http://identifiers.org/pombase/>
PREFIX ena: <http://www.ebi.ac.uk/ena/data/view/>
PREFIX ec: <http://www.expasy.org/enzyme/>
PREFIX uniprotkb: <http://identifiers.org/uniprot/>
PREFIX mgi: <http://identifiers.org/mgi/>
PREFIX gomodel: <http://model.geneontology.org/>
PREFIX kegg_pathway: <http://identifiers.org/kegg.pathway/>
PREFIX doi: <http://dx.doi.org/>
PREFIX panther: <http://identifiers.org/panther.family/>
PREFIX fb: <http://identifiers.org/flybase/>
PREFIX ensembl: <http://identifiers.org/ensembl/>
PREFIX cgd: <http://identifiers.org/cgd/>
PREFIX gr_gene: <http://identifiers.org/gramene.gene/>
PREFIX kegg_enzyme: <http://identifiers.org/kegg.enzyme/>
PREFIX cacao: <http://gowiki.tamu.edu/wiki/index.php/>
PREFIX po_ref: <http://planteome.org/po_ref/>
PREFIX uniprotkb-subcell: <http://www.uniprot.org/locations/>
PREFIX nif_subcellular: <http://www.neurolex.org/wiki/>
PREFIX genedb: <http://identifiers.org/genedb/>
PREFIX apidb_plasmodb: <http://www.plasmodb.org/gene/>
PREFIX rnacentral: <http://rnacentral.org/rna/>
PREFIX rfam: <http://rfam.sanger.ac.uk/family/>
PREFIX obo_sf2_po: <http://sourceforge.net/p/obo/plant-ontology-po-term-requests/>
PREFIX uniparc: <http://www.uniprot.org/uniparc/>
PREFIX gdb: <http://www.gdb.org/gdb-bin/genera/accno?accessionNum=GDB:>
PREFIX dbsnp: <http://identifiers.org/dbsnp/>
PREFIX maizegdb_locus: <http://identifiers.org/maizegdb.locus/>
PREFIX mo: <http://mged.sourceforge.net/ontologies/MGEDontology.php#>
PREFIX plana_ref: <http://purl.obolibrary.org/obo/plana/references/>
PREFIX cas: <http://identifiers.org/cas/>
PREFIX complexportal: <https://www.ebi.ac.uk/complexportal/complex/>
PREFIX jstor: <http://www.jstor.org/stable/>
PREFIX gr_qtl: <http://identifiers.org/gramene.qtl/>
PREFIX vbrc: <http://vbrc.org/query.asp?web_id=VBRC:>
PREFIX eo_git: <https://github.com/Planteome/plant-environment-ontology/issues/>
PREFIX tgd: <http://identifiers.org/tgd/>
PREFIX obo_sf2_peco: <https://sourceforge.net/p/obo/plant-environment-ontology-eo/>
PREFIX metacyc: <http://identifiers.org/metacyc/>
PREFIX omim: <http://omim.org/entry/>
PREFIX intact: <http://identifiers.org/intact/>
PREFIX ensembl_geneid: <http://www.ensembl.org/id/>
PREFIX uniprotkb-kw: <http://www.uniprot.org/keywords/>
PREFIX eupathdb: <http://eupathdb.org/gene/>""", str(pl).strip())
コード例 #5
0
ファイル: local_context.py プロジェクト: vemonet/PyShEx
import sys
from rdflib import URIRef, XSD
from pyshex import PrefixLibrary

""" This module is used to test the PrefixLibrary's ability to inject namespaces directoy into the containing module 
It is used in conjunction with test_prefixlib.test_add_to_module """

pl = PrefixLibrary("""
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX prov: <http://www.w3.org/ns/prov#>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX pr: <http://www.wikidata.org/prop/reference/>
PREFIX prv: <http://www.wikidata.org/prop/reference/value/>
PREFIX pv: <http://www.wikidata.org/prop/value/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX gw: <http://genewiki.shape/>""")

pl.add_to_object(sys.modules[__name__])

def sample(name: str) -> URIRef:
    return PROV[name]

pl.add_rdf('@prefix XSD: <http://nonxml.com/item#> .')

pl.add_to_object(sys.modules[__name__], override=True)

def rdf(name: str) -> URIRef:
    return XSD[name]