첫째, 당신은 사용할 수 없습니다 "를 공급 업체 2와 우편 번호 334 "및"공급 업체 2 (우편 번호 335 포함) "가 동일한 개인이기 때문에"우편 번호 334 및 우편 번호 334가있는 공급 업체 2 "가 두 번 모두 신청서에 표시됩니다.
실현 방법에는 몇 가지가 있습니다. 일반 예나 API와
:
Model model; // your model
Resource supplierClass = model.getResource(YOUR_NS + "Supplier");
Resource buyerClass = model.getResource(YOUR_NS + "Buyer");
Resource procClass = model.getResource(YOUR_NS + "Procedure");
Property zipCodeProp = model.getProperty(YOUR_NS + "zipCode");
Property hasBuyerProp = model.getProperty(YOUR_NS + "hasBuyer");
Property hasSupplierProp = model.getProperty(YOUR_NS + "hasSupplier");
StmtIterator iter =
model.listStatements(new SimpleSelector(null, zipCodeProp, "333"));
while (iter.hasNext()) {
Resource subject = iter.next().getSubject();
if (!subject.hasProperty(RDF.type))
continue;
Resource subjectClass = subject.getPropertyResourceValue(RDF.type);
SimpleSelector sel;
if (subjectClass.equals(supplierClass))
sel = new SimpleSelector(null, hasSupplierProp, subject);
else if (subjectClass.equals(buyerClass))
sel = new SimpleSelector(null, hasBuyerProp, subject);
else
continue;
StmtIterator innerIter = model.listStatements(sel);
while (innerIter.hasNext()) {
Resource proc = innerIter.next().getSubject();
if (!proc.hasProperty(RDF.type) ||
!proc.getPropertyResourceValue(RDF.type).equals(procClass))
continue;
// now you can retrieve linked entities from this procedure
}
}
그리고 SPARQL 질의 : ARQ의 추가 사용에
PREFIX yourns: <YOUR_NS>
SELECT DISTINCT ?proc
{
?proc a yourns:Procedure;
yourns:hasBuyer ?buyer;
yourns:hasSupplier ?supplier.
?supplier zipCode ?supplierZip.
?buyer zipCode ?buyerZip.
FILTER (?supplierZip = '333' || ?buyerZip = '333')
}
:
Query query = QueryFactory.create(queryString);
QueryExecution qe = QueryExecutionFactory.create(query, model);
ResultSet results = qe.execSelect();
while (results.hasNext()) {
QuerySolution qs = results.next();
Resource proc = qs.getResource("proc");
// now again you can retrieve linked entities
}
하이 레, 답장을 보내 주셔서 감사합니다. 이번 주에 저는 당신의 해결책을 시도 할 수 없습니다. 다음 주에 내가 갈거야. NG PS : suplier number를 변경하는 것을 잊었습니다.) –