예제 #1
0
    def test_biolink_rdf(self):
        """ Test the rdf generator for the biolink model """
        self.single_file_generator('ttl', RDFGenerator, serialize_args=dict(
            context=["https://w3id.org/linkml/meta.context.jsonld"]), comparator=compare_rdf)

        # Validate the RDF against the Biolink ShEx
        if SKIP_SHEX_VALIDATION:
            print(f'* test_biolink_rdf: {SKIP_SHEX_VALIDATION_REASON}')
        else:
            g = Graph()
            g.load(env.expected_path('biolink_model.ttl'), format='ttl')
            focus = BIOLINK_NS.biolink_model
            start = METAMODEL_NAMESPACE.SchemaDefinition
            results = ShExEvaluator(g, env.expected_path('biolink_model.shexj'), focus, start).evaluate(debug=False)
            self.assertTrue(self._evaluate_shex_results(results))
예제 #2
0
    def test_biolink_correct_rdf(self):
        """ Test some conforming RDF  """
        self.single_file_generator('shexj', ShExGenerator, format='json')  # Make sure ShEx is current

        shex_file = env.expected_path('biolink-model.shexj')

        focus = "http://identifiers.org/drugbank:DB00005"
        start = BIOLINK_NS.Drug
        evaluator = ShExEvaluator(None, shex_file, focus, start)

        rdf_file = env.input_path('probe.ttl')
        results = evaluator.evaluate(rdf_file, debug=False)
        self.assertTrue(self._evaluate_shex_results(results))
예제 #3
0
    def test_biolink_shex_incorrect_rdf(self):
        """ Test some non-conforming RDF  """
        self.single_file_generator('shexj', ShExGenerator, format='json')
        shex_file = env.expected_path('biolink-model.shexj')

        focus = "http://identifiers.org/drugbank:DB00005"
        start = BIOLINK_NS.Drug
        evaluator = ShExEvaluator(None, shex_file, focus, start)

        # incorrect.ttl has 16 error lines (more or less).
        rdf_file = env.temp_file_path('incorrect.ttl')
        errs_file = env.temp_file_path('incorrect.errs')
        results = evaluator.evaluate(rdf_file)
        self.assertFalse(self._evaluate_shex_results(results, printit=False))
        self.assertEqual(1, len(results))
        self.assertTrue('Unmatched triples in CLOSED shape' in results[0].reason)
        ntabs = results[0].reason.count('\n\t')
        self.assertEqual(13, ntabs)
        if not os.path.exists(errs_file):
            with open(errs_file, 'w') as f:
                f.write(shex_results_as_string(results[0]))