All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.aksw.jena_sparql_api.geo.MainGeomizerTest Maven / Gradle / Ivy

package org.aksw.jena_sparql_api.geo;

import java.util.Map;
import java.util.Set;

import org.aksw.jena_sparql_api.core.QueryExecutionFactory;
import org.aksw.jena_sparql_api.http.QueryExecutionFactoryHttp;
import org.aksw.jena_sparql_api.lookup.LookupService;
import org.aksw.jena_sparql_api.lookup.LookupServiceCacheMem;
import org.aksw.jena_sparql_api.lookup.LookupServicePartition;
import org.aksw.jena_sparql_api.lookup.LookupServiceUtils;
import org.aksw.jena_sparql_api.mapper.MappedConcept;
import org.aksw.jena_sparql_api.utils.TripleUtils;

import org.apache.jena.graph.Graph;
import org.apache.jena.graph.GraphUtil;
import org.apache.jena.graph.Node;
import org.apache.jena.graph.Triple;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.util.FileManager;
import com.vividsolutions.jts.geom.Geometry;

//Query query = QueryFactory.create("Prefix geo:  Prefix dbpo:  Select ?s ?w { ?s a dbpo:Castle ; geo:geometry ?w }");


public class MainGeomizerTest {

    public static LookupService createLookupService(QueryExecutionFactory sparqlService, MappedConcept mc) {
        //LookupService result = LookupServiceUtilsGeo.createGeoLookupService(sparqlService, mc);
        LookupService result = LookupServiceUtils.createLookupService(sparqlService, mc);
        result = LookupServicePartition.create(result, 30, 5);
        result = LookupServiceCacheMem.create(result);

        return result;
    }


    public static void main(String[] args) {



        //Model model = FileManager.get().loadModel("/home/raven/Projects/Eclipse/24-7-platform/link-specifications/dbpedia-linkedgeodata-university/positive.nt");
        Model model = FileManager.get().loadModel("/home/raven/Projects/Eclipse/24-7-platform/link-specifications/dbpedia-linkedgeodata-airport/positive.nt");

        Graph graph = model.getGraph();
        Set triples = graph.find(null, null, null).toSet();

        triples = TripleUtils.swap(triples);

        QueryExecutionFactory sparqlServiceSource = new QueryExecutionFactoryHttp("http://dbpedia.org/sparql", "http://dbpedia.org");
        QueryExecutionFactory sparqlServiceTarget = new QueryExecutionFactoryHttp("http://linkedgeodata.org/sparql", "http://linkedgeodata.org");

        /*
        LookupService ls = new LookupServiceSparqlQuery(sparqlService, query, var);
        ls = LookupServicePartition.create(ls, 1);
        ls = LookupServiceCacheMem.create(ls);
        */

        MappedConcept mcA = GeoMapSupplierUtils.mcWgsGeometry;
        MappedConcept mcB = GeoMapSupplierUtils.mcOgcGeometry;

        LookupService lsA = createLookupService(sparqlServiceSource, mcA);
        LookupService lsB = createLookupService(sparqlServiceTarget, mcB);

//        Collection test = Collections.singletonList(NodeFactory.createURI("http://linkedgeodata.org/triplify/node404580641"));
//        Map testResult = lsB.apply(test);
//        System.out.println("YAY: " + testResult);
//
//        if(true) {
//            return;
//        }

        Map map = LinkGeomizer.geomize(triples, lsA, lsB);

        Model result = ModelFactory.createDefaultModel();
        Set ts = GeoMapSupplierUtils.geomizedToRdf(map);
        GraphUtil.add(result.getGraph(), ts.iterator());

        result.write(System.out, "N-TRIPLES");


    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy