2011-08-07 2 views
1

먼저 꺼내기. 나는 예나를 처음 사용합니다. I've는 온톨로지 및 i've 4 개 클래스, 절차, 구매자, 공급자를 작성 않는 암호에는 다음과 같은 속성이 i've 우편 번호 :문자열이 포함 된 도메인을 나열하십시오.

  1. 절차 hasBuyer 구매자를
  2. 절차 hasSupplier 공급
  3. 공급 업체 hasZipCode 우편 번호
  4. 구매자 hasZipCode 우편 번호는

는 내가 알고 싶은 문자열 "3333"를 포함하는 모든 도메인을 반환 예나 가장 좋은 방법을 키우면. 예를 들어

:

  • 절차 1 우편 번호와 우편 번호 333 supplier2와 우편 번호 333, 공급자 1 구매자 1을 334
  • 절차 2는 우편 번호 (331), 공급자와 구매자 2를 가지고 우편 번호와 우편 번호 334 supplier2 2 335
  • 335

결과 ㄱ해야 절차 3은 우편 번호와 우편 번호 333 supplier3와 우편 번호 333, 공급자 1 구매자 3을 E :

  • 절차 - Procedure1 및 Procedure3
  • 역할 - Buyer1 및 구매자는 3
  • 공급 업체 - supplier1

NG 모든

답변

1

첫째, 당신은 사용할 수 없습니다 "를 공급 업체 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 
} 
+0

하이 레, 답장을 보내 주셔서 감사합니다. 이번 주에 저는 당신의 해결책을 시도 할 수 없습니다. 다음 주에 내가 갈거야. NG PS : suplier number를 변경하는 것을 잊었습니다.) –