问题如下:在解析 sparql 查询时,我得到了简化的 ast,我需要将其传递给第三方库进行进一步处理,但开箱即用的功能 (rdf4j) 不允许在机器中传输 ast - 可读格式,只有tex,我想以json格式接收。
StringBuilder qb = new StringBuilder();
qb.append(" PREFIX has_vaccine_allergen: <http://purl.obolibrary.org/obo/VO_0000531>\n" +
" PREFIX chicken_egg_protein_allergen: <http://purl.obolibrary.org/obo/VO_0000912> \n" +
" SELECT distinct ?vaccine_label ?vaccine \n" +
" FROM <http://purl.obolibrary.org/obo/merged/VO>\n" +
" WHERE {\n" +
" ?vaccine rdfs:label ?vaccine_label .\n" +
" ?vaccine rdfs:subClassOf ?vaccine_restriction .\n" +
" ?vaccine_restriction owl:onProperty has_vaccine_allergen:; owl:someValuesFrom chicken_egg_protein_allergen: .\n" +
"\t}");
SPARQLParser parser = new SPARQLParser();
ParsedTupleQuery q = (ParsedTupleQuery)parser.parseQuery(qb.toString(), null);
TupleExpr te = q.getTupleExpr();
System.out.println(te);
代码执行结果:
SelectQuery
[PrefixDecl (prefix=has_vaccine_allergen), PrefixDecl (prefix=chicken_egg_protein_allergen), SelectQuery]
Distinct
Projection
ProjectionElemList
ProjectionElem "vaccine_label"
ProjectionElem "vaccine"
Join
Join
Join
StatementPattern
Var (name=vaccine)
Var (name=_const_9285ccfc_uri, value=http://www.w3.org/2000/01/rdf-schema#label, anonymous)
Var (name=vaccine_label)
StatementPattern
Var (name=vaccine)
Var (name=_const_4592be07_uri, value=http://www.w3.org/2000/01/rdf-schema#subClassOf, anonymous)
Var (name=vaccine_restriction)
我需要把它变成 json 格式
繁华开满天机
相关分类