来源--Java错误:找不到符号



这个问题很愚蠢,但我真的不明白为什么会发生这种情况。

我正在学习使用Provence工具箱,它的API可以在这里找到:http://openprovenance.org/java/site/0_6_0/apidocs/index.html

首先,使用doConversions()方法进行测试,所有这些问题都源于此。

我正在尝试使用方法阅读出处文件(.prvn)

readDocumentFromFile(String filename)

并且它返回一个文档。然后我使用Document类中的方法来获取文档中的所有prov语句和bundle,这将返回文档中的语句或bundle的列表。

但当我编译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

即CCD_ 2类。有人能解释为什么会发生这种情况吗?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

最新更新