Wednesday, October 17, 2012
start reasoner in virtuoso
load Model from virtuoso
VirtGraph set = new VirtGraph(GraphIri, "jdbc:virtuoso://" + uriServer + ":"
+ portJDBC + "", db_user, db_pass);
System.out.println("Start inference!");
Reasoner reasoner = PelletReasonerFactory.theInstance().create();
reasoner = reasoner.bindSchema(set);
InfModel infModel = ModelFactory.createInfModel(reasoner, modelVirtuoso);
System.out.println("Stop inference!");
Model m2 = vd.getNamedModel(GraphIri);
save inference in virtuoso
System.out.print("instancias "+m2.size());
if(m2.containsAll(infModel)){ System.out.print("no hay inferencia ");
}else{ System.out.print("hay inferencia "); }
if(m2.containsAny(infModel)){ System.out.print("es correcto ");
}else{ System.out.print("es incorrecto "); }
Model inferido = infModel.difference(m2);
m2.add(inferido);
Monday, October 15, 2012
install virtuoso in windows
Download database virtuoso in http://sourceforge.net/projects/virtuoso/files/latest/download
unzip in virtuoso-opensource and add in variable path virtuoso-opensource\lib
copy database/virtuoso.ini as demo.ini in virtuoso-opensource
remove in file demo.ini all character ../
open cmd admin mode
http://networkadminkb.com/KB/a47/how-to-allow-users-to-enumerate-service-remotely.aspx
unable to open sthe service control manager
execute in virtuoso-opensource ./bin/virtuoso-t.exe -c demo -I Demo -S create
the service has been register
start service openlink virtuoso server [Demo]
open http://localhost:8890/
load OWL file model in virtuoso
If you try save a model from OWL file in Virtuoso with class
VirtuosoUpdateFactory or VirtuosoQueryExecutionFactory this fail.
http://answers.semanticweb.com/questions/10520/virtrdfinsert-examples
http://answers.semanticweb.com/questions/12513/graph-in-virtuoso
To load in virtuoso used VirtDataSource
VirtDataSource vd = new VirtDataSource("jdbc:virtuoso://localhost:1111", "dba", "dba");
ModelMaker maker = ModelFactory.createMemModelMaker();
Model m = maker.createModel(BASE, false);
//load owl file in model M
FileInputStream fis = new FileInputStream (getClass().getClassLoader().getResource("file.owl").getFile());
m.read(fis ,null);
fis.close();
//TODO: if exist BASE in virtuoso FAIL
//to erase datas conductor SQL> RDF_GLOBAL_RESET ();
Model m2 =vd.getNamedModel(BASE);
if(m2 == null)
vd.addNamedModel(BASE, m);
VirtuosoUpdateFactory or VirtuosoQueryExecutionFactory this fail.
http://answers.semanticweb.com/questions/10520/virtrdfinsert-examples
http://answers.semanticweb.com/questions/12513/graph-in-virtuoso
To load in virtuoso used VirtDataSource
VirtDataSource vd = new VirtDataSource("jdbc:virtuoso://localhost:1111", "dba", "dba");
ModelMaker maker = ModelFactory.createMemModelMaker();
Model m = maker.createModel(BASE, false);
//load owl file in model M
FileInputStream fis = new FileInputStream (getClass().getClassLoader().getResource("file.owl").getFile());
m.read(fis ,null);
fis.close();
//TODO: if exist BASE in virtuoso FAIL
//to erase datas conductor SQL> RDF_GLOBAL_RESET ();
Model m2 =vd.getNamedModel(BASE);
if(m2 == null)
vd.addNamedModel(BASE, m);
Wednesday, October 3, 2012
Neo4j + Sesame + OwlApi + Pellet
To create inference in pellet and export this inferece to Neo4j with sail connector
function OpenSail
function import ontology
Map<String, String> config = new HashMap<String, String>();
config.put("allow_store_upgrade", "true");
graph = new MyNeo4jGraph("data/graph.db", 100000, config);
graph.setCheckElementsInTransaction(true);
sail = new GraphSail<Neo4jGraph>(graph);
// sail.
sail.initialize();
SailRepository repository = new SailRepository(sail);
connection = repository.getConnection();
connection.setAutoCommit(true);
connection.add(getClass().getClassLoader().getResource("Prueba.owl"),
"etiqueta", RDFFormat.RDFXML);
System.out.println("Import stopped ...");
connection.commit();
function Sparql
TupleQuery durationquery = connection
.prepareTupleQuery(
QueryLanguage.SPARQL,
"PREFIX : <http://www.semanticweb.org/ontologies/2012/8/Prueba.owl#> "
+ "PREFIX Prueba: <http://www.semanticweb.org/ontologies/2012/8/Prueba.owl#> "
+ "PREFIX owl: <http://www.w3.org/2002/07/owl#> "
+ "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> "
+ "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> "
+ "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> "
+ "SELECT ?person " + "WHERE { " +
" Prueba:Jean Prueba:hasSibling ?person . "+
"}");
TupleQueryResult result = durationquery.evaluate();
while (result.hasNext()) {
BindingSet binding = result.next();
System.out.println(binding.getBinding("person").getValue());
Assert.assertEquals("Assert ", binding.getBinding("person").getValue().toString(),
"http://www.semanticweb.org/ontologies/2012/8/Prueba.owl#Gemma");
}
reasoner
//prepare ontology and reasoner
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
//OWLOntology ontology = manager.loadOntologyFromOntologyDocument(IRI.create(BASE_URL));
OWLOntology ontology = manager.loadOntologyFromOntologyDocument(
IRI.create(getClass().getClassLoader().getResource("Prueba.owl")));
System.out.println(" Load ontology" );
OWLReasonerFactory reasonerFactory = PelletReasonerFactory.getInstance();
System.out.println(" Load reasoner" );
OWLReasoner reasoner = reasonerFactory.createReasoner(ontology, new SimpleConfiguration());
OWLDataFactory factory = manager.getOWLDataFactory();
PrefixOWLOntologyFormat pm = manager.getOntologyFormat(ontology).asPrefixOWLOntologyFormat();
pm.setDefaultPrefix(BASE_URL + "#");
//get class and its individuals
OWLClass personClass = factory.getOWLClass(":Person", pm);
pm.setDefaultPrefix("http://www.semanticweb.org/ontologies/2012/8/Prueba.owl#");
OWLObjectProperty hasSibling = factory.getOWLObjectProperty(":hasSibling", pm);
//export pellet inference to sesame sail neo4j
for (OWLNamedIndividual person : reasoner.getInstances(personClass, false).getFlattened()) {
System.out.println("person : " + renderer.render(person));
for (Node<OWLNamedIndividual> siblings : reasoner.getObjectPropertyValues(person, hasSibling)) {
for (OWLNamedIndividual sibling : siblings.getEntities()) {
System.out.println("Person has sibling: " + sibling.getIRI());
Map<OWLObjectPropertyExpression, Set<OWLIndividual>> assertedValues = person.getObjectPropertyValues(ontology);
for (OWLObjectProperty objProp : ontology.getObjectPropertiesInSignature(true)) {
for (OWLNamedIndividual ind : reasoner.getObjectPropertyValues(person, objProp).getFlattened()) {
if (assertedValues.get(objProp)==null ) {//inference
System.out.println("inferred object property for :"
+ renderer.render(objProp) + " -> " + renderer.render(ind));
ValueFactory mValueFactory = connection.getValueFactory();
org.openrdf.model.URI predicate = mValueFactory.createURI(hasSibling.getIRI().toURI().toString());
Resource subject = mValueFactory.createURI(person.getIRI().toURI().toString()); // mValueFactory.createURI(subj.getIRI().toURI().toString());
Resource resource = mValueFactory.createBNode();
Value object = null;
object = mValueFactory.createURI(ind.getIRI().toURI().toString());
try {
System.out.println("Triplet --"+subject+"--"+predicate+"--"+object+"--"+resource+"--");
connection.add(subject, predicate, object,resource);
} catch (RepositoryException e) {
System.out.println(e);
}
}else{//asserted
boolean asserted = assertedValues.get(objProp).contains(ind);
System.out.println((asserted ? "asserted" : "inferred") + " object property for Martin: "
+ renderer.render(objProp) + " -> " + renderer.render(ind));
}
}
}
}
}
}
Assert.assertTrue(reasoner.isConsistent());
Monday, October 1, 2012
java.lang.UnsatisfiedLinkError:
I have a next error with maven and eclipse
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.10:test (default-test) on project database: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.10:test failed: An API incompatibility was encountered while executing org.apache.maven.plugins:maven-surefire-plugin:2.10:test: java.lang.UnsatisfiedLinkError: java.io.WinNTFileSystem.createFileExclusively(Ljava/lang/String;Z)Z
Change version SE java to JDK or other version java. This fix the problem.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.10:test (default-test) on project database: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.10:test failed: An API incompatibility was encountered while executing org.apache.maven.plugins:maven-surefire-plugin:2.10:test: java.lang.UnsatisfiedLinkError: java.io.WinNTFileSystem.createFileExclusively(Ljava/lang/String;Z)Z
Change version SE java to JDK or other version java. This fix the problem.
Friday, September 21, 2012
NoClassDefFoundError: org/apache/lucene/util/Version
I make a project with blueprint-neo4j-graph and pellet , but pellet use lucene-core 2.3.1 and blueprint-neo4j-graph use lucene-core 3.5.0
I have a new error in neo4j to load lucene version
Caused by: java.lang.NoClassDefFoundError: org/apache/lucene/util/Version
at org.neo4j.index.impl.lucene.LuceneDataSource.<clinit>(LuceneDataSource.java:110)
at org.neo4j.index.lucene.LuceneIndexProvider.load(LuceneIndexProvider.java:70)
at org.neo4j.kernel.InternalAbstractGraphDatabase$DefaultKernelExtensionLoader.loadIndexImplementations(InternalAbstractGraphDatabase.java:1191)
at org.neo4j.kernel.InternalAbstractGraphDatabase$DefaultKernelExtensionLoader.init(InternalAbstractGraphDatabase.java:1163)
at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.init(LifeSupport.java:382)
... 39 more
Caused by: java.lang.ClassNotFoundException: org.apache.lucene.util.Version
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 44 more
I have pellet dependence
<dependency>
<groupId>com.owldl</groupId>
<artifactId>pellet</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.tinkerpop.blueprints</groupId>
<artifactId>blueprints-neo4j-graph</artifactId>
<version>2.1.0</version>
</dependency>
With plugin m2e resolve depencence add this code in pom.xml project
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-core</artifactId>
<version>3.5.0</version>
</dependency>
</dependencies>
</dependencyManagement>
Thursday, September 6, 2012
Install cassandra database
To install cassandra database distribution http://www.datastax.com/download/community
Dont work in 32 bit architecture. java Heap space error
To see web service
http://<publicIP>:8888/opscenter/
Ubuntu 12, 64 bit
Before
**** remove version of java openjdk and install java oracle
sudo apt-ger purge openjdk*
java 7
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get install oracle-java7-installer
****openssl python
sudo apt-get install libssl0.9.8
sudo apt-get install sysstat
sudo apt-get install python-cql
****Install cassandra, DataStax Community distribution of Cassandra. Read more in http://www.datastax.com/docs/1.1/install/install_deb
sudo apt-get install dsc1.1
****install web service. Read more in http://www.datastax.com/docs/opscenter/install/install_deb
sudo apt-get install opscenter-free
***web service configure
sudo vi /etc/opscenter/opscenterd.conf
***add in file
[cassandra]
seed_hosts=publicIP
[logging]
level=INFO
[jmx]
port =7199
***configure cassadra
sudo vi /etc/cassandra/cassandra.yaml
***change IP and localhost for publiIP
***start cassandra
sudo service cassandra start
***node cassandra
nodetool ring -h publicIP
**start web
sudo service opscenterd start
*** check web service
wget http://publicIP:8888/
***to see log
/var/log/opscenter/opscenterd.log
*** to start client cassandra
cassandra-cli -h publicIP -p 9160
***to see log of cassandra
/var/log/cassandra/output.log
/var/log/cassandra/system.log
*** delete database cassandra if you want , stop service before
sudo bash -c '/var/lib/cassandra/data/system/*'
Dont work in 32 bit architecture. java Heap space error
To see web service
http://<publicIP>:8888/opscenter/
Ubuntu 12, 64 bit
Before
**** remove version of java openjdk and install java oracle
sudo apt-ger purge openjdk*
java 7
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get install oracle-java7-installer
****openssl python
sudo apt-get install libssl0.9.8
sudo apt-get install sysstat
sudo apt-get install python-cql
****Install cassandra, DataStax Community distribution of Cassandra. Read more in http://www.datastax.com/docs/1.1/install/install_deb
sudo apt-get install dsc1.1
****install web service. Read more in http://www.datastax.com/docs/opscenter/install/install_deb
sudo apt-get install opscenter-free
***web service configure
sudo vi /etc/opscenter/opscenterd.conf
***add in file
[cassandra]
seed_hosts=publicIP
[logging]
level=INFO
[jmx]
port =7199
***configure cassadra
sudo vi /etc/cassandra/cassandra.yaml
***change IP and localhost for publiIP
***start cassandra
sudo service cassandra start
***node cassandra
nodetool ring -h publicIP
**start web
sudo service opscenterd start
*** check web service
wget http://publicIP:8888/
***to see log
/var/log/opscenter/opscenterd.log
*** to start client cassandra
cassandra-cli -h publicIP -p 9160
***to see log of cassandra
/var/log/cassandra/output.log
/var/log/cassandra/system.log
*** delete database cassandra if you want , stop service before
sudo bash -c '/var/lib/cassandra/data/system/*'
Subscribe to:
Posts (Atom)