这是一个非常愚蠢的问题,但是我真的不明白为什么会这样。
我正在学习使用Provenance工具箱,其API可以在以下位置找到:
http://openprovenance.org/java/site/0_6_0/apidocs/index.html
首先,使用doConversions()
方法进行测试,所有这些问题均来自此。
我正在尝试通过使用方法来阅读出处文档(.provn)
readDocumentFromFile(String filename)
并返回一个文档。然后,我使用Document类中的方法来获取文档中的所有prov语句和捆绑包,这将返回文档中的语句或捆绑包的列表。
但是,当我编译java文件(在下面找到)时,它会抛出错误:
/home/hduser/Downloads/ProvToolbox-Tutorial1-0.6.1/src/main/java/org/openprovenance/prov/tutorial/tutorial1/Little.java:[17,36] error: cannot find symbol
这是
NamedBundle
类。有人可以解释为什么会这样吗? NamedBundle类在软件包org.openprovenance.prov.model
中通过在命令行中使用命令:
mvn clean install
编译代码。 Maven 1.3版用于编译此代码。另一个问题:NamedBundle类扩展了StatementOrBundle类,从代码中可以看到,temp.get(i)返回
List<StatementOrBundle>
中的元素我想使用NamedBundle类中的方法,该怎么做?
这是代码:
package org.openprovenance.prov.tutorial.tutorial1;
import java.util.*;
import org.openprovenance.prov.interop.InteropFramework;
import org.openprovenance.prov.interop.InteropFramework.ProvFormat;
//import org.openprovenance.prov.model.*;
import org.openprovenance.prov.model.Agent;
import org.openprovenance.prov.model.Document;
import org.openprovenance.prov.model.Entity;
import org.openprovenance.prov.model.Namespace;
import org.openprovenance.prov.model.QualifiedName;
import org.openprovenance.prov.model.ProvFactory;
import org.openprovenance.prov.model.StatementOrBundle;
import org.openprovenance.prov.model.WasAttributedTo;
import org.openprovenance.prov.model.WasDerivedFrom;
import org.openprovenance.prov.model.NamedBundle;
/**
* A little provenance goes a long way.
* ProvToolbox Tutorial 1: creating a provenance document in Java and serializing it
* to SVG (in a file) and to PROVN (on the console).
*
* @author lucmoreau
* @see <a href="http://blog.provbook.org/2013/10/11/a-little-provenance-goes-a-long-way/">a-little-provenance-goes-a-long-way blog post</a>
*/
public class Little {
public static final String PROVBOOK_NS = "http://www.provbook.org";
public static final String PROVBOOK_PREFIX = "provbook";
public static final String JIM_PREFIX = "jim", TRUNG_PREFIX = "trung";
public static final String JIM_NS = "http://www.cs.rpi.edu/~hendler/", TRUNG_NS = "abcd";
private final ProvFactory pFactory;
private final Namespace ns;
public Little(ProvFactory pFactory) {
this.pFactory = pFactory;
ns=new Namespace();
ns.addKnownNamespaces();
ns.register(PROVBOOK_PREFIX, PROVBOOK_NS);
ns.register(JIM_PREFIX, JIM_NS);
ns.register(TRUNG_PREFIX, TRUNG_NS);
}
public QualifiedName qn(String n) {
return ns.qualifiedName(PROVBOOK_PREFIX, n, pFactory);
}
public Document makeDocument() {
/***********Testing code************/
Entity book = pFactory.newEntity(ns.qualifiedName(TRUNG_PREFIX, "PROV Definition", pFactory));
Agent trung = pFactory.newAgent(qn("Trung"), "Trung Nguyen");
WasAttributedTo attr3 = pFactory.newWasAttributedTo(null,
book.getId(),
trung.getId());
/********************************/
Entity quote = pFactory.newEntity(qn("a-little-provenance-goes-a-long-way"));
//quote.setValue(pFactory.newValue("A little provenance goes a long way",
// pFactory.getName().XSD_STRING));
Agent paul = pFactory.newAgent(qn("Paul"), "Paul Groth");
WasAttributedTo attr1 = pFactory.newWasAttributedTo(null,
quote.getId(),
paul.getId());
Entity original = pFactory.newEntity(ns.qualifiedName(JIM_PREFIX,"LittleSemanticsWeb.html",pFactory));
Agent luc = pFactory.newAgent(qn("Luc"), "Luc Moreau");
WasAttributedTo attr2 = pFactory.newWasAttributedTo(null,
quote.getId(),
luc.getId());
WasDerivedFrom wdf = pFactory.newWasDerivedFrom(quote.getId(), original.getId());
WasDerivedFrom wdf1 = pFactory.newWasDerivedFrom(book.getId(), quote.getId());
Document document = pFactory.newDocument();
document.getStatementOrBundle()
.addAll(Arrays.asList(new StatementOrBundle[] { quote,
book,
trung,
luc,
paul,
attr1,
attr2,
attr3,
original,
wdf,
wdf1}));
document.setNamespace(ns);
return document;
}
public void doConversions(Document document, String file) {
InteropFramework intF=new InteropFramework();
intF.writeDocument(file, document);
intF.writeDocument(System.out, ProvFormat.PROVN, document);
//intF.writeDocument("trang.txt", document);
//System.out.println();
System.out.println("\n*********Get Doc's Elements****************");
//Document trung_doc = intF.readDocumentFromFile("trung.provn");
//Document trung_doc = intF.readDocumentFromFile("ss_expanded_prov.provn");
Document trung_doc = intF.readDocumentFromFile("ss_reputation_binding.provn");
List temp = trung_doc.getStatementOrBundle();
System.out.println(temp.size());
for (int i = 0; i < temp.size(); i++){
//System.out.println(temp.get(i).getStatement().size());
if (temp.get(i) instanceof Entity){
Entity temp_ent = (Entity) temp.get(i);
System.out.println("\nEntity's Attributes:");
System.out.println("Entity "+ i +": ");
System.out.println("Value: "+temp_ent.getValue());
System.out.println("Other: "+temp_ent.getOther());
System.out.println("Type: "+temp_ent.getType());
System.out.println("Label: "+temp_ent.getLabel());
System.out.println("Location: "+temp_ent.getLocation());
System.out.println("ID: "+temp_ent.getId());
System.out.println("Kind: "+temp_ent.getKind());
}
}
System.out.println("*************************");
}
public void closingBanner() {
System.out.println("");
System.out.println("*************************");
}
public void openingBanner() {
System.out.println("*************************");
System.out.println("* Converting document ");
System.out.println("*************************");
}
public static void main(String [] args) {
if (args.length!=1) throw new UnsupportedOperationException("main to be called with filename");
String file=args[0];
Little little=new Little(InteropFramework.newXMLProvFactory());
little.openingBanner();
Document document = little.makeDocument();
little.doConversions(document, file);
little.closingBanner();
}
}
最佳答案
你可以尝试导入
import org.openprovenance.prov.model.Bundle;
代替
import org.openprovenance.prov.model.NamedBundle;
我可以看到一个提交注释:将NamedBundle重命名为Bundle(并将Bundle重命名为BundleEntity)
https://github.com/lucmoreau/ProvToolbox/commit/b6053f8ba8f5762c1d7d64aae79a5d7f0de2046a