新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   >>中国XML论坛<<     W3CHINA.ORG讨论区     计算机科学论坛     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> 本版讨论Semantic Web(语义Web,语义网或语义万维网, Web 3.0)及相关理论,如:Ontology(本体,本体论), OWL(Web Ontology Langauge,Web本体语言), Description Logic(DL, 描述逻辑),RDFa,Ontology Engineering等。
    [返回] 中文XML论坛 - 专业的XML技术讨论区W3CHINA.ORG讨论区 - Web新技术讨论『 Semantic Web(语义Web)/描述逻辑/本体 』 → 用SPARQL语句出现如下错误:ERROR: operator does not exist: integer = character varying 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 5263 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: 用SPARQL语句出现如下错误:ERROR: operator does not exist: integer = character varying 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     bzbc 帅哥哟,离线,有人找我吗?
      
      
      等级:大三暑假(TOFEL考了660分!)
      文章:151
      积分:921
      门派:XML.ORG.CN
      注册:2006/4/15

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给bzbc发送一个短消息 把bzbc加入好友 查看bzbc的个人资料 搜索bzbc在『 Semantic Web(语义Web)/描述逻辑/本体 』的所有贴子 引用回复这个贴子 回复这个贴子 查看bzbc的博客楼主
    发贴心情 用SPARQL语句出现如下错误:ERROR: operator does not exist: integer = character varying

    import org.mindswap.pellet.query.QueryEngine;
    import org.mindswap.pellet.query.QueryResults;

    import com.hp.hpl.jena.db.DBConnection;
    import com.hp.hpl.jena.db.ModelRDB;
    import com.hp.hpl.jena.ontology.OntModel;
    import com.hp.hpl.jena.query.Query;
    import com.hp.hpl.jena.query.QueryExecution;
    import com.hp.hpl.jena.query.QueryExecutionFactory;
    import com.hp.hpl.jena.query.QueryFactory;
    import com.hp.hpl.jena.query.QuerySolutionMap;
    import com.hp.hpl.jena.query.ResultSet;
    import com.hp.hpl.jena.query.ResultSetFormatter;
    import com.hp.hpl.jena.rdf.model.InfModel;
    import com.hp.hpl.jena.rdf.model.Model;
    import com.hp.hpl.jena.rdf.model.ModelFactory;
    import com.hp.hpl.jena.rdf.model.ModelMaker;
    import com.hp.hpl.jena.rdf.model.RDFNode;
    import com.hp.hpl.jena.reasoner.Reasoner;
    import com.hp.hpl.jena.reasoner.ReasonerRegistry;
    import com.hp.hpl.jena.sparql.core.ResultBinding;
    import com.hp.hpl.jena.sparql.lang.rdql.WorkingVar;
    import com.hp.hpl.jena.sparql.util.IndentedWriter;


    /**
    * Uses Jena's OWL reasoner to find all hyponyms of a given word
    */
    public class FindInferredHypernyms  {
      /** MySQL driver classname */
     private static final String mysqlDriver = "org.postgresql.Driver";

     /** URL of database to use */
     private static final String DB_URL = "jdbc:postgresql://localhost/test";
     private static final String DB_TYPE = "PostgreSQL";

     /** User credentials */
     private static final String DB_USER = "ijd";
     private static final String DB_PASSWORD = "123";                  
      /** Name of the Jena model to create */
       private static final String MODEL_NAME = "wordnet";
       static public final String NL = System.getProperty("line.separator");
      /**
       * Finds the hypernyms of a wordform given on the commandline
       */
      public static void main(String args[]) {

        // Check that the user provided a single argument
       /* if (args.length != 1) {
          printUsage();
          System.exit(-1);
        }*/
        try {
          // Instantiate database driver
          Class.forName(mysqlDriver);                 
        } catch (ClassNotFoundException e) {
          System.err.println("MySQL driver class not found");
          System.exit(-1);
        }
        // Get a connection to the db
        DBConnection connection = new DBConnection(DB_URL, DB_USER, DB_PASSWORD, DB_TYPE);
        // Grab a ref to the existing model
       // ModelRDB model = ModelRDB.open(connection,MODEL_NAME);
        // Make a new model to act as an OWL ontology for WordNet
        ModelMaker maker = ModelFactory.createModelRDBMaker(connection);
        Model model = maker.openModel("wordnet",true);
        OntModel wnOntology = ModelFactory.createOntologyModel();

        // Use OntModel's convenience method to describe WordNet's hyponymOf property as transitive
        wnOntology.createTransitiveProperty(WordnetVocab.hyponymOf.getURI());

        // Create a reasoner bound to the ontology
        Reasoner owlReasoner = ReasonerRegistry.getOWLReasoner();
        Reasoner wnReasoner = owlReasoner.bindSchema(wnOntology);

        // Use the reasoner to create a inference model
        InfModel infModel = ModelFactory.createInfModel(wnReasoner, model);

        // Create a query
        String prolog = "PREFIX wn: <http://www.cogsci.princeton.edu/~wn/schema/>";
        String queryString = prolog+ NL +
          "SELECT ?hypernym ?definition " +
          "WHERE {?firstconcept wn:wordForm ?hyponym. " +
          "?firstconcept wn:hyponymOf ?secondconcept. " +
          "?secondconcept wn:wordForm ?hypernym." +
          "?secondconcept  wn:glossaryEntry ?definition.}";
        Query query = QueryFactory.create(queryString);

     query.serialize(new IndentedWriter(System.out, true));
     System.out.println();
        // Need to set the source since the query does not.  
        // Bind the "hyponym" term in the query to the user's input

       /* ResultbindingIml initialBindings = new ResultBindingImpl();
         RDFNode hyponym = null;
      initialBindings.add("hyponym", hyponym);*/
         QueryExecution qexec =
             QueryExecutionFactory.create(query, infModel);
     
        ResultSet results =qexec.execSelect();
         // Output the results
         System.out.println("Hypernyms found for ");
         ResultSetFormatter.out(System.out, results,query);

         System.out.println();
         while (results.hasNext()) {
           ResultBinding binding = (ResultBinding)results.next();
           Object wordform = binding.get("hypernym");
           Object definition = binding.get("definition");
           System.out.println(wordform+":\t"+definition);
         }
         try {
           // Close the database connection
           connection.close();
         } catch (java.sql.SQLException e) {}
       }

     // doSearch(model,args[0]);

      private static void printUsage() {
        System.out.print("\nUsage:\n");
        System.out.print("\tFindInferredHypernyms <hyponym>\n\n");
        System.out.print("\thyponym\t- The word to find hypernyms for\n");
      }
    }
      1 PREFIX  wn:   <http://www.cogsci.princeton.edu/~wn/schema/>
      2
      3 SELECT  ?hypernym ?definition
      4 WHERE
      5   { ?firstconcept
      6               wn:wordForm       ?hyponym ;
      7               wn:hyponymOf      ?secondconcept .
      8     ?secondconcept
      9               wn:wordForm       ?hypernym ;
    10               wn:glossaryEntry  ?definition .
    11   }

    Hypernyms found for
    Exception in thread "main" org.postgresql.util.PSQLException: ERROR: operator does not exist: integer = character varying
     at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1592)
     at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1327)
     at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:192)
     at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:451)
     at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:350)
     at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:343)
     at com.hp.hpl.jena.db.impl.SQLCache.executeSQL(SQLCache.java:720)
     at com.hp.hpl.jena.db.impl.PSet_ReifStore_RDB.findReifTripleMatch(PSet_ReifStore_RDB.java:213)
     at com.hp.hpl.jena.db.impl.SpecializedGraphReifier_RDB.find(SpecializedGraphReifier_RDB.java:414)
     at com.hp.hpl.jena.db.GraphRDB.graphBaseFind(GraphRDB.java:436)
     at com.hp.hpl.jena.graph.impl.GraphBase.find(GraphBase.java:240)
     at com.hp.hpl.jena.reasoner.FGraph.find(FGraph.java:42)
     at com.hp.hpl.jena.reasoner.rulesys.impl.RETEEngine.fastInit(RETEEngine.java:135)
     at com.hp.hpl.jena.reasoner.rulesys.FBRuleInfGraph.prepare(FBRuleInfGraph.java:460)
     at com.hp.hpl.jena.reasoner.rulesys.FBRuleInfGraph.findWithContinuation(FBRuleInfGraph.java:551)
     at com.hp.hpl.jena.reasoner.rulesys.FBRuleInfGraph.graphBaseFind(FBRuleInfGraph.java:583)
     at com.hp.hpl.jena.graph.impl.GraphBase.find(GraphBase.java:257)
     at com.hp.hpl.jena.graph.query.QueryTriple$SimpleApplyer.find(QueryTriple.java:141)
     at com.hp.hpl.jena.graph.query.QueryTriple$SimpleApplyer.applyToTriples(QueryTriple.java:145)
     at com.hp.hpl.jena.graph.query.StageElement$FindTriples.run(StageElement.java:50)
     at com.hp.hpl.jena.graph.query.PatternStageBase.run(PatternStageBase.java:53)
     at com.hp.hpl.jena.graph.query.PatternStageBase$Work.run(PatternStageBase.java:104)
     at com.hp.hpl.jena.graph.query.PatternStageBase$PatternStageThread.run(PatternStageBase.java:88)
    com.hp.hpl.jena.shared.JenaException: Exception during database access
     at com.hp.hpl.jena.db.impl.PSet_ReifStore_RDB.findReifTripleMatch(PSet_ReifStore_RDB.java:216)
     at com.hp.hpl.jena.db.impl.SpecializedGraphReifier_RDB.find(SpecializedGraphReifier_RDB.java:414)
     at com.hp.hpl.jena.db.GraphRDB.graphBaseFind(GraphRDB.java:436)
     at com.hp.hpl.jena.graph.impl.GraphBase.find(GraphBase.java:240)
     at com.hp.hpl.jena.reasoner.FGraph.find(FGraph.java:42)
     at com.hp.hpl.jena.reasoner.rulesys.impl.RETEEngine.fastInit(RETEEngine.java:135)
     at com.hp.hpl.jena.reasoner.rulesys.FBRuleInfGraph.prepare(FBRuleInfGraph.java:460)
     at com.hp.hpl.jena.reasoner.rulesys.FBRuleInfGraph.findWithContinuation(FBRuleInfGraph.java:551)
     at com.hp.hpl.jena.reasoner.rulesys.FBRuleInfGraph.graphBaseFind(FBRuleInfGraph.java:583)
     at com.hp.hpl.jena.graph.impl.GraphBase.find(GraphBase.java:257)
     at com.hp.hpl.jena.graph.query.QueryTriple$SimpleApplyer.find(QueryTriple.java:141)
     at com.hp.hpl.jena.graph.query.QueryTriple$SimpleApplyer.applyToTriples(QueryTriple.java:145)
     at com.hp.hpl.jena.graph.query.StageElement$FindTriples.run(StageElement.java:50)
     at com.hp.hpl.jena.graph.query.PatternStageBase.run(PatternStageBase.java:53)
     at com.hp.hpl.jena.graph.query.PatternStageBase$Work.run(PatternStageBase.java:104)
     at com.hp.hpl.jena.graph.query.PatternStageBase$PatternStageThread.run(PatternStageBase.java:88)
    Caused by: org.postgresql.util.PSQLException: ERROR: operator does not exist: integer = character varying
     at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1592)
     at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1327)
     at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:192)
     at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:451)
     at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:350)
     at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:343)
     at com.hp.hpl.jena.db.impl.SQLCache.executeSQL(SQLCache.java:720)
     at com.hp.hpl.jena.db.impl.PSet_ReifStore_RDB.findReifTripleMatch(PSet_ReifStore_RDB.java:213)
     ... 15 more
    com.hp.hpl.jena.shared.QueryStageException: rethrew: com.hp.hpl.jena.shared.JenaException: Exception during database access
     at com.hp.hpl.jena.graph.query.BufferPipe$Finished.<init>(BufferPipe.java:30)
     at com.hp.hpl.jena.graph.query.BufferPipe.close(BufferPipe.java:61)
     at com.hp.hpl.jena.graph.query.PatternStageBase.run(PatternStageBase.java:57)
     at com.hp.hpl.jena.graph.query.PatternStageBase$Work.run(PatternStageBase.java:104)
     at com.hp.hpl.jena.graph.query.PatternStageBase$PatternStageThread.run(PatternStageBase.java:88)
    Caused by: com.hp.hpl.jena.shared.JenaException: Exception during database access
     at com.hp.hpl.jena.db.impl.PSet_ReifStore_RDB.findReifTripleMatch(PSet_ReifStore_RDB.java:216)
     at com.hp.hpl.jena.db.impl.SpecializedGraphReifier_RDB.find(SpecializedGraphReifier_RDB.java:414)
     at com.hp.hpl.jena.db.GraphRDB.graphBaseFind(GraphRDB.java:436)
     at com.hp.hpl.jena.graph.impl.GraphBase.find(GraphBase.java:240)
     at com.hp.hpl.jena.reasoner.FGraph.find(FGraph.java:42)
     at com.hp.hpl.jena.reasoner.rulesys.impl.RETEEngine.fastInit(RETEEngine.java:135)
     at com.hp.hpl.jena.reasoner.rulesys.FBRuleInfGraph.prepare(FBRuleInfGraph.java:460)
     at com.hp.hpl.jena.reasoner.rulesys.FBRuleInfGraph.findWithContinuation(FBRuleInfGraph.java:551)
     at com.hp.hpl.jena.reasoner.rulesys.FBRuleInfGraph.graphBaseFind(FBRuleInfGraph.java:583)
     at com.hp.hpl.jena.graph.impl.GraphBase.find(GraphBase.java:257)
     at com.hp.hpl.jena.graph.query.QueryTriple$SimpleApplyer.find(QueryTriple.java:141)
     at com.hp.hpl.jena.graph.query.QueryTriple$SimpleApplyer.applyToTriples(QueryTriple.java:145)
     at com.hp.hpl.jena.graph.query.StageElement$FindTriples.run(StageElement.java:50)
     at com.hp.hpl.jena.graph.query.PatternStageBase.run(PatternStageBase.java:53)
     ... 2 more
    Caused by: org.postgresql.util.PSQLException: ERROR: operator does not exist: integer = character varying
     at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1592)
     at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1327)
     at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:192)
     at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:451)
     at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:350)
     at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:343)
     at com.hp.hpl.jena.db.impl.SQLCache.executeSQL(SQLCache.java:720)
     at com.hp.hpl.jena.db.impl.PSet_ReifStore_RDB.findReifTripleMatch(PSet_ReifStore_RDB.java:213)
     ... 15 more
    望高手解决,深表谢意。


       收藏   分享  
    顶(0)
      




    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2008/4/18 8:24:00
     
     jpz6311whu 帅哥哟,离线,有人找我吗?
      
      
      
      威望:9
      等级:研三(收到微软亚洲研究院的Offer了)(版主)
      文章:1718
      积分:10610
      门派:W3CHINA.ORG
      注册:2005/4/12

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给jpz6311whu发送一个短消息 把jpz6311whu加入好友 查看jpz6311whu的个人资料 搜索jpz6311whu在『 Semantic Web(语义Web)/描述逻辑/本体 』的所有贴子 引用回复这个贴子 回复这个贴子 查看jpz6311whu的博客2
    发贴心情 
    有可能是postgresql版本问题,你可以换一个jena文档中说明明确支持的版本试试
    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2008/4/19 13:15:00
     
     bzbc 帅哥哟,离线,有人找我吗?
      
      
      等级:大三暑假(TOFEL考了660分!)
      文章:151
      积分:921
      门派:XML.ORG.CN
      注册:2006/4/15

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给bzbc发送一个短消息 把bzbc加入好友 查看bzbc的个人资料 搜索bzbc在『 Semantic Web(语义Web)/描述逻辑/本体 』的所有贴子 引用回复这个贴子 回复这个贴子 查看bzbc的博客3
    发贴心情 
    谢谢,果然是高手,希望Postgre解决这个问题
    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2008/4/23 22:57:00
     
     GoogleAdSense
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 Semantic Web(语义Web)/描述逻辑/本体 』的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/12/18 22:55:05

    本主题贴数3,分页: [1]

    管理选项修改tag | 锁定 | 解锁 | 提升 | 删除 | 移动 | 固顶 | 总固顶 | 奖励 | 惩罚 | 发布公告
    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    78.125ms