def check_rule_with_data(rule_path, data_path): r = load_yamldown(rule_path) schema = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../../metadata/rules.schema.yaml") validate(r, schema) if not rule.sparql_from(r): raise Exception("No SPARQL impl for rule {}".format(rule_path)) g = rdflib.graph.ConjunctiveGraph() test_data_graph = g.parse(data_path, format="ttl", publicID="http://geneontology.org/rules/test") test_data_graph.add((term.URIRef("http://model.geneontology.org/rules/test"), term.URIRef("http://model.geneontology.org/graphType"), term.URIRef("http://model.geneontology.org/gafCam"))) test_data_graph.add((term.URIRef("http://model.geneontology.org/rules/test"), term.URIRef("http://www.w3.org/2000/01/rdf-schema#"), term.Literal("test_graph.ttl"))) results = g.query(rule.sparql_from(r)) return results
def check_rule_with_data(rule_path, data_path): r = load_yamldown(rule_path) schema = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../../metadata/rules.schema.yml") validate(r, schema) if not rule.sparql_from(r): raise Exception("No SPARQL impl for rule {}".format(rule_path)) g = rdflib.graph.ConjunctiveGraph() test_data_graph = g.parse(data_path, format="ttl", publicID="http://geneontology.org/rules/test") test_data_graph.add((term.URIRef("http://geneontology.org/rules/test"), term.URIRef("http://geneontology.org/graphType"), term.URIRef("http://geneontology.org/gafCam"))) results = g.query(rule.sparql_from(r)) return results
def group(endpoint, rules_dir, schema, verbose, out) -> None: gorules_paths = glob.glob(os.path.join(rules_directory(path=rules_dir), "gorule-*.md")) rules = [load_yamldown(path) for path in gorules_paths if rule.sparql_from(load_yamldown(path))] s = schema if schema else SCHEMA results = [] for r in rules: validate(r, s) result = rule.test_rule(r, endpoint) results.append(result) click.echo(result.short_summary()) if result.returned and verbose: click.echo(result.verbose_readable()) if out: json.dump(rule.generate_results_json(results), out, indent=4)
def test(ctx, endpoint, rule_path, verbose, schema, out): r = load_yamldown(rule_path) s = schema if schema else SCHEMA validate(r, s) if not rule.sparql_from(r): raise click.ClickException("No SPARQL implementation for this rule.") result = rule.test_rule(r, endpoint) click.echo(result.short_summary()) if result.returned and verbose: click.echo(result.verbose_readable()) if out: json.dump(result.jsonify(), out, indent=4) if result.passing in ["Warn", "Fail"]: ctx.exit(1)