Last active
November 13, 2015 05:43
-
-
Save abargnesi/5a08aebfb49c41e498ac to your computer and use it in GitHub Desktop.
SPARQL ftw!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| PREFIX belv: <http://www.openbel.org/vocabulary/> | |
| PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> | |
| PREFIX skos: <http://www.w3.org/2004/02/skos/core#> | |
| CONSTRUCT { | |
| ?s rdf:type belv:UUIDConcept . | |
| ?s skos:inScheme ?uuidURI . | |
| ?eq rdf:type belv:UUIDConcept . | |
| ?eq skos:inScheme ?uuidURI . | |
| ?uuidURI rdf:type belv:UUIDConceptScheme . | |
| ?uuidURI rdf:type skos:ConceptScheme . | |
| ?uuidURI rdf:type belv:belv:UUIDConcept . | |
| } | |
| WHERE { | |
| ?s rdf:type belv:NamespaceConcept . | |
| FILTER NOT EXISTS { | |
| ?s rdf:type belv:UUIDConcept . | |
| } | |
| BIND(URI(CONCAT("http://www.openbel.org/bel/uuid/", StrUUID())) AS ?uuidURI) . | |
| ?s skos:exactMatch ?eq . | |
| FILTER NOT EXISTS { | |
| ?eq rdf:type belv:UUIDConcept . | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| PREFIX belv: <http://www.openbel.org/vocabulary/> | |
| PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> | |
| PREFIX skos: <http://www.w3.org/2004/02/skos/core#> | |
| INSERT { | |
| ?s rdf:type belv:UUIDConcept . | |
| ?s skos:inScheme ?uuidURI . | |
| ?eq rdf:type belv:UUIDConcept . | |
| ?eq skos:inScheme ?uuidURI . | |
| ?uuidURI rdf:type belv:UUIDConceptScheme . | |
| ?uuidURI rdf:type skos:ConceptScheme . | |
| ?uuidURI rdf:type belv:belv:UUIDConcept . | |
| } | |
| WHERE { | |
| ?s rdf:type belv:NamespaceConcept . | |
| FILTER NOT EXISTS { | |
| ?s rdf:type belv:UUIDConcept . | |
| } | |
| BIND(URI(CONCAT("http://www.openbel.org/bel/uuid/", StrUUID())) AS ?uuidURI) . | |
| ?s skos:exactMatch ?eq . | |
| FILTER NOT EXISTS { | |
| ?eq rdf:type belv:UUIDConcept . | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package org.openbel.resource_reasoner; | |
| import org.apache.jena.query.*; | |
| import org.apache.jena.rdf.model.Model; | |
| import org.apache.jena.rdf.model.ResIterator; | |
| import org.apache.jena.rdf.model.Resource; | |
| import org.apache.jena.update.UpdateAction; | |
| import org.apache.jena.update.UpdateFactory; | |
| import org.apache.jena.update.UpdateRequest; | |
| import org.apache.jena.vocabulary.RDF; | |
| import java.io.IOException; | |
| import java.io.InputStream; | |
| import java.util.Scanner; | |
| import static org.openbel.resource_reasoner.RDFFunctions.createResource; | |
| import static org.openbel.resource_reasoner.RDFFunctions.log; | |
| public class UUID { | |
| public static final Resource BELV_NamespaceConcept = createResource("http://www.openbel.org/vocabulary/NamespaceConcept"); | |
| public static void main(String[] args) throws IOException { | |
| Dataset ds = RDFFunctions.dataset_("rdf_db"); | |
| InputStream sparqlInsert = Main.class.getResourceAsStream("/insert_uuid.sparql"); | |
| String insertUUID = new Scanner(sparqlInsert, "UTF-8").useDelimiter("\\A").next(); | |
| UpdateRequest req = UpdateFactory.create(insertUUID, Syntax.syntaxSPARQL_11); | |
| Model m = ds.getDefaultModel(); | |
| ResIterator concepts = m.listSubjectsWithProperty(RDF.type, BELV_NamespaceConcept); | |
| long count = 0; | |
| while (concepts.hasNext()) { | |
| Resource concept = concepts.nextResource(); | |
| QuerySolutionMap binding = new QuerySolutionMap(); | |
| binding.add("s", concept); | |
| UpdateAction.execute(req, ds, binding); | |
| log("Created UUID cluster around %s", concept.toString()); | |
| count += 1; | |
| if (count % 1000 == 0) { | |
| log("%s UUID clusters", count); | |
| } | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT (COUNT(?s) AS ?uuidCount) | |
| WHERE { | |
| ?s a <http://www.openbel.org/vocabulary/UUIDConceptScheme> . | |
| } | |
| # Count is 157302. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment