如何使用耶拿图书馆将三元组插入议会三重商店

时间:2013-12-23 15:26:01

标签: java geospatial jena triplestore

您好我想添加基于空间的三重

http://www.izmirdeafet.com/Disaster htp://www.opengis.net/ont/geosparql#asWKT> "htp://www.opengis.net/def/crs/OGC/1.3/CRS84 POINT (8.46035239692792 51.48661096320327)"^^<http://www.opengis.net/ont/sf#wktLiteral>

在下面的java代码中使用jena库进入议会三重商店但是ı在下面已经出错了。我有基于空间的本体论,它已经添加到三重商店。

public static void main(String[] args) {       
    // set to false when running the second time to avoid recreating the graphs/index 
    boolean firstTime = true;
    // create spatial index factory and configure for GeoSPARQL. This is used
    // by the GraphStore whenever a new named graph is created.
    SpatialIndexFactory factory = new SpatialIndexFactory();
    Properties properties = new Properties();
    properties.setProperty(Constants.GEOMETRY_INDEX_TYPE,
                     Constants.GEOMETRY_INDEX_RTREE);
    properties.setProperty(Constants.GEOSPARQL_ENABLED,
                     Boolean.TRUE.toString());
    factory.configure(properties);

    // register factory
    IndexFactoryRegistry.getInstance().register(factory);

    // create a Parliament graph and graph store
    //KbGraph graph= KbGraphFactory.createNamedGraph();
    KbGraph graph = 
    KbGraphFactory.createDefaultGraph("file:C:\\ParliamentKB\\data\\");
    KbGraphStore graphStore = new KbGraphStore(graph);
    graphStore.initialize();

    if (firstTime) {
        // create spatial index from factory
        SpatialIndex index = factory.createIndex(graph, null);

        // register index with IndexManager
        IndexManager.getInstance().register(graph, null, factory, index);

        // the following tells the graph store that the graph is now an
        // indexing graph. This is necessary so that the next time Parliament
        // loads, the index is read in automatically.
        graphStore.setIndexingEnabled(KbGraphStore.DEFAULT_GRAPH_NODE, true);
    }

    // create a Jena model
    Model model = ModelFactory.createModelForGraph(graph);

    // load data
    String fileName =
    "C:\\Users\\Can\\Desktop\\DisasterOntologyEnglish\\disaster.rdf";
    RDFFormat dataFormat = RDFFormat.parseFilename(fileName);
    FileManager.get().readModel(model, fileName, dataFormat.toString());

    // get index and print size
    System.out.println(IndexManager.getInstance().
        getIndexes(graph).get(0).size());

    // do a spatial query
    String query = ""
    + "\nPREFIX my:  <http://somewhere/ApplicationSchema#>"
    + "\nPREFIX geo: <http://www.opengis.net/ont/OGC-GeoSPARQL/1.0/>"
    + "\nPREFIX geof: 
     <http://www.opengis.net/def/queryLanguage/OGC-GeoSPARQL/1.0/function/>"
    + "\nSELECT ?f" + "\nWHERE { my:A my:hasExactGeometry ?aGeom ."
    + "\n        ?aGeom geo:asWKT ?aWKT ."
    + "\n        ?f my:hasExactGeometry ?fGeom ."
    + "\n        ?fGeom geo:asWKT ?fWKT ."
    + "\n        FILTER (geof:sf-contains(?aWKT, ?fWKT) &&"
    + "\n                !sameTerm(?aGeom, ?fGeom)) " + "\n}";

    Query q = QueryFactory.create(query, Syntax.syntaxARQ);
    ResultSet rs = QueryExecutionFactory.create(q, model).execSelect();
    while (rs.hasNext()) {
        System.out.println(rs.nextSolution());
    }
}

错误

   Exception in thread "main" java.lang.UnsatisfiedLinkError: 
    no Parliament in   java.library.path
    at java.lang.ClassLoader.loadLibrary(Unknown Source)
    at java.lang.Runtime.loadLibrary0(Unknown Source)
    at java.lang.System.loadLibrary(Unknown Source)
    at com.bbn.parliament.jni.Config.<clinit>(Config.java:184)
    at com.bbn.parliament.jena.graph.KbGraphFactory.getKbConfigForDefaultGraph
         (KbGraphFactory.java:81)
    at com.bbn.parliament.jena.graph.KbGraphFactory.createDefaultGraph
         (KbGraphFactory.java:38)
    at com.disaster.demo.GeoSPARQLTest.main(GeoSPARQLTest.java:46)

我认为问题来自createdefaultgraph部分:

你说的是ParliamentConfig.txt

取道的路径
  KbGraph graph = KbGraphFactory.createDefaultGraph("file:C:\\ParliamentKB\\data\\");

我这样编码,但它没有用。

3 个答案:

答案 0 :(得分:1)

未满足的链接错误可能表示它无法在java路径中找到Parliament.dll。

检查此SO以获取有关java路径中dll的详细信息: java.lang.UnsatisfiedLinkError no *****.dll in java.library.path

另外,您是否关注议会设置指南? http://parliament.semwebcentral.org/ParliamentUserGuide.pdf

你也可能想确保你使用正确的dll ...它已经有一段时间了,所以我可能错了,但我认为有32位和64位版本。

答案 1 :(得分:0)

在议会用户指南(http://parliament.semwebcentral.org/ParliamentUserGuide.pdf)中,第26页的第2.8节专门用于解决这些UnsatisfiedLinkError问题。

答案 2 :(得分:0)

根据抛出的异常,您的问题是由于配置/建立议会环境变量的差距。请遵循上面答案中提供的ParliamentUserGuide。一旦完成,您将得到并输出如下:

INFO [main] (KbGraphStore.java:163) - Adding named graph: <http://parliament.semwebcentral.org/parliament#MasterGraph> (graphDir = "master") Apr 07, 2014 2:17:05 PM org.geotools.referencing.factory.epsg.ThreadedEpsgFactory <init> INFO: Setting the EPSG factory org.geotools.referencing.factory.epsg.ThreadedHsqlEpsgFactory to a 1800000ms timeout Apr 07, 2014 2:17:05 PM org.geotools.referencing.factory.epsg.ThreadedEpsgFactory <init> INFO: Setting the EPSG factory org.geotools.referencing.factory.epsg.DefaultFactory to a 1800000ms timeout Apr 07, 2014 2:17:05 PM org.geotools.referencing.factory.epsg.ThreadedHsqlEpsgFactory createDataSource INFO: Building new data source for org.geotools.referencing.factory.epsg.ThreadedHsqlEpsgFactory Apr 07, 2014 2:17:05 PM org.geotools.referencing.factory.epsg.ThreadedHsqlEpsgFactory createBackingStore INFO: Building backing store for org.geotools.referencing.factory.epsg.ThreadedHsqlEpsgFactory Apr 07, 2014 2:17:05 PM org.geotools.referencing.factory.epsg.ThreadedHsqlEpsgFactory createBackingStore INFO: Creating cached EPSG database version 7.5.0. This operation may take a few minutes... Apr 07, 2014 2:17:06 PM org.geotools.referencing.factory.PropertyAuthorityFactory <init> WARNING: Axis elements found in a wkt definition, the force longitude first axis order hint might not be respected: PROJCS["Google Projection",GEOGCS["WGS 84",DATUM["World Geodetic System 1984",SPHEROID["WGS 84", 6378137.0, 298.257223563, AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich", 0.0, AUTHORITY["EPSG","8901"]],UNIT["degree", 0.017453292519943295],AXIS["Geodetic longitude", EAST],AXIS["Geodetic latitude", NORTH],AUTHORITY["EPSG","4326"]],PROJECTION["Popular Visualisation Pseudo Mercator", AUTHORITY["EPSG","1024"]],PARAMETER["semi_minor", 6378137.0],PARAMETER["latitude_of_origin", 0.0],PARAMETER["central_meridian", 0.0],PARAMETER["scale_factor", 1.0],PARAMETER["false_easting", 0.0],PARAMETER["false_northing", 0.0],UNIT["m", 1.0]] 只有在此之后,您才能对创建的模型执行任何操作,例如添加三元组和查询。

除了具有空间属性的Triple:假设您想要向个人添加空间坐标(例如individual),您可以使用以下代码段:

import com.bbn.parliament.jena.graph.index.spatial.geosparql.datatypes.WKTLiteral;
import com.bbn.parliament.jena.graph.index.spatial.geosparql.vocabulary.*;
.
.
.
WKTLiteral geoLiteral = new WKTLiteral();
String value="Point(22.5 88.5)";// OR "POLYGON((22.5 88.5, 88.5 99.5, 99.5 22.5))"
individual.addLiteral(Geo.asWKT, model.createTypedLiteral(value, geoLiteral));

诀窍:

KbGraph graph = KbGraphFactory.createDefaultGraph("file:C:\\ParliamentKB\\data\\"); 不行,我不知道为什么!所以你可能需要在ParliamentCOnfig.txt中指定epath。

相关问题