Jena,DBpedia:RDF 和模型名称

发布于 2024-10-17 12:46:46 字数 1131 浏览 1 评论 0原文

我在我的应用程序中使用 dbpedia,并使用 Jena 进行语义逻辑。

在耶拿,这些类是:

模型:一组语句 http://jena.sourceforge.net/javadoc /com/hp/hpl/jena/rdf/model/Model.html 资源http: //jena.sourceforge.net/javadoc/com/hp/hpl/jena/rdf/model/Resource.html

在dbpedia中,资源的rdf代码是这样的: 例如 http://dbpedia.org/resource/Frederick_of_Sweden 变成 http://dbpedia.org/data/Frederick_of_Sweden.rdf

如果我调用:

Model model = maker.createModel( "http://dbpedia.org/data/Frederick_of_Sweden.rdf")

一个模型创建名称“http://dbpedia.org/data/Frederick_of_Sweden.rdf”。 但我实际上需要将其称为“http://dbpedia.org/resource/Frederick_of_Sweden”,以与 rdf 语句保持一致。如何命名模型?

如果我想导航图表并到达其他节点,存储这些语句的最佳方式是什么?我是否需要为每个 dbpedia 资源建立一个单独的模型,或者我可以将所有语句合并到一个大模型中吗?

感谢您的任何提示! 穆隆

I'm using dbpedia in my app, and I'm using Jena for the semantic logic.

In Jena, the classes are:

Model: a set of statements
http://jena.sourceforge.net/javadoc/com/hp/hpl/jena/rdf/model/Model.html
Resource: http://jena.sourceforge.net/javadoc/com/hp/hpl/jena/rdf/model/Resource.html

In dbpedia, the rdf code of a resource is this:
e.g. http://dbpedia.org/resource/Frederick_of_Sweden
becomes http://dbpedia.org/data/Frederick_of_Sweden.rdf

If I call:

Model model = maker.createModel( "http://dbpedia.org/data/Frederick_of_Sweden.rdf")

A model with the name 'http://dbpedia.org/data/Frederick_of_Sweden.rdf' is created.
But I actually need to call it 'http://dbpedia.org/resource/Frederick_of_Sweden', to be consistent with the rdf statements. How do I name a model?

If I want to navigate the graph and reach other nodes, which is the best way to store these statements? Do I need a separate model for each dbpedia resource, or can I merge all the statements in one big model?

Thanks for any hint!
Mulone

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡墨 2024-10-24 12:46:46

我认为创建模型的方式不会真正影响下载数据的方式。您可以使用您喜欢的 URI 标识符创建模型。

在这里,我展示了一个示例,它可以提供一些关于如何将从 DBPedia 获取三元组的方式与将它们存储在后端系统中的方式分开的想法。

根据您的问题,我假设您正在使用数据库后端,因此我的代码针对耶拿的此类后端。

import java.sql.SQLException;
import com.hp.hpl.jena.util.FileManager;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.SimpleSelector;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.StmtIterator;
import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.db.DBConnection;
import com.hp.hpl.jena.rdf.model.ModelMaker;
import com.hp.hpl.jena.rdf.model.ModelFactory;

public class TestJena {

    public static void main(String[] args) throws java.lang.ClassNotFoundException, java.sql.SQLException {
        Class.forName("com.mysql.jdbc.Driver");            

        //The database backend initialization.
        DBConnection connection = new DBConnection(MY_DB, USER, PASS, "mysql");
        ModelMaker dbMaker = ModelFactory.createModelRDBMaker(connection);

        //A file manager to get the triples from the DBPedia revolvable URI. 
        FileManager fManager = FileManager.get();
        fManager.addLocatorURL();
        Model linkedDataModel =
              fManager.loadModel("http://dbpedia.org/data/Frederick_of_Sweden.rdf");


        //Now we copy the in-memory model into our DB backend. 
        //When the model is created you can give it the name that you like.
        Model dbModel = 
              dbMaker.createModel("http://dbpedia.org/resource/Frederick_of_Sweden");

        dbModel.add(linkedDataModel);

        StmtIterator iter = dbModel.listStatements();
        while (iter.hasNext()) {
            Statement stmt = iter.nextStatement();
            System.out.println(stmt);
        }


        linkedDataModel.close();
        dbModel.close();
        connection.close();
}

这个例子打印...

[http://dbpedia.org/resource/Frederick_i_of_sweden, http://dbpedia.org/ontology/wikiPageRedirects, http://dbpedia.org/resource/Frederick_of_Sweden]
[http://dbpedia.org/resource/Frederick_I_%28of_Sweden%29, http://dbpedia.org/ontology/wikiPageRedirects, http://dbpedia.org/resource/Frederick_of_Sweden]
[http://dbpedia.org/resource/Frederick_I,_Landgrave_of_Hesse-Kassel, http://dbpedia.org/ontology/wikiPageRedirects, http://dbpedia.org/resource/Frederick_of_Sweden]
[http://dbpedia.org:8890/data/Frederick_of_Sweden.rdf, http://xmlns.com/foaf/0.1/primaryTopic, http://dbpedia.org/resource/Frederick_of_Sweden]
(....)

I don't think the way you create your models really affect the way you download the data. You can create your model with the URI identifier that you like.

Here I show an example that can give some ideas of how to separate the way you get your triples from DBPedia and the way you store them in your backend system.

From your question I assume you are using a database backend so my code is targeted to that kind of backend in Jena.

import java.sql.SQLException;
import com.hp.hpl.jena.util.FileManager;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.SimpleSelector;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.StmtIterator;
import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.db.DBConnection;
import com.hp.hpl.jena.rdf.model.ModelMaker;
import com.hp.hpl.jena.rdf.model.ModelFactory;

public class TestJena {

    public static void main(String[] args) throws java.lang.ClassNotFoundException, java.sql.SQLException {
        Class.forName("com.mysql.jdbc.Driver");            

        //The database backend initialization.
        DBConnection connection = new DBConnection(MY_DB, USER, PASS, "mysql");
        ModelMaker dbMaker = ModelFactory.createModelRDBMaker(connection);

        //A file manager to get the triples from the DBPedia revolvable URI. 
        FileManager fManager = FileManager.get();
        fManager.addLocatorURL();
        Model linkedDataModel =
              fManager.loadModel("http://dbpedia.org/data/Frederick_of_Sweden.rdf");


        //Now we copy the in-memory model into our DB backend. 
        //When the model is created you can give it the name that you like.
        Model dbModel = 
              dbMaker.createModel("http://dbpedia.org/resource/Frederick_of_Sweden");

        dbModel.add(linkedDataModel);

        StmtIterator iter = dbModel.listStatements();
        while (iter.hasNext()) {
            Statement stmt = iter.nextStatement();
            System.out.println(stmt);
        }


        linkedDataModel.close();
        dbModel.close();
        connection.close();
}

This example prints ...

[http://dbpedia.org/resource/Frederick_i_of_sweden, http://dbpedia.org/ontology/wikiPageRedirects, http://dbpedia.org/resource/Frederick_of_Sweden]
[http://dbpedia.org/resource/Frederick_I_%28of_Sweden%29, http://dbpedia.org/ontology/wikiPageRedirects, http://dbpedia.org/resource/Frederick_of_Sweden]
[http://dbpedia.org/resource/Frederick_I,_Landgrave_of_Hesse-Kassel, http://dbpedia.org/ontology/wikiPageRedirects, http://dbpedia.org/resource/Frederick_of_Sweden]
[http://dbpedia.org:8890/data/Frederick_of_Sweden.rdf, http://xmlns.com/foaf/0.1/primaryTopic, http://dbpedia.org/resource/Frederick_of_Sweden]
(....)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文