2011-08-07 111 views
1

首先我要對耶拿的所有新手進行初始化。從來就創建了一個本體和從來就4類,過程,買方,供應商和郵政編碼Code.And從來就以下屬性:列出包含字符串的域名

  1. 步驟hasBuyer買家
  2. 步驟hasSupplier供應商
  3. 供應商hasZipCode郵編
  4. 買家hasZipCode郵編

我想知道it's在耶拿的最佳方法返回包含字符串「3333」的所有域。

例如:

  • 步驟1具有買方1與郵政編碼333,供應商1郵政編碼333和supplier2與郵政編碼334
  • 程序2有買方2與郵政編碼331,供應商2郵政編碼334和supplier2與郵政編碼335
  • 過程3具有買方3與郵政編碼333,供應商1郵政編碼333和supplier3與郵政編碼335

的結果必須b E:

  • 程序 - PROCEDURE1和Procedure3
  • 買家 - Buyer1和買家3
  • 供應商 - supplier1

NG

回答

1

首先,你不能使用「供應商2與郵政編碼334「,然後」供應商2與郵政編碼335「,因爲它是相同的個人,並且您在兩次申請中將看到」供應商2與郵政編碼334和郵政編碼334「。

有一些變體的實現。

帶滑動耶拿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查詢:

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') 
} 

進一步使用ARQ的:

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:我忘記更改更新號碼了) –