Tuesday, October 30, 2012

Cassandra keys in Unix/linux server and client in java windows

In this link talk about to count in rows in cassandra. But there a little problem when Unix database and client java Windows. The serialize UUID dont work.
byte[] start = null;
byte[] lastEnd = null;
int count = 0;
while (true) {
RangeSlicesQuery rsq = HFactory
 .createRangeSlicesQuery(keyspaceOperator,
       me.prettyprint.cassandra.serializers.BytesArraySerializer.get(), StringSerializer.get(),
 StringSerializer.get());
 rsq.setColumnFamily("columnFamily");
 rsq.setColumnNames("uuid","idUser","timestamp","urlPageVisited","processed");
 rsq.setKeys(start, null);
 rsq.setReturnKeysOnly(); // Return column names instead of values
 rsq.setRowCount(3); // Arbitrary default
 OrderedRows rows = rsq.execute().get();
 int rowCount = rows.getCount();

if (rowCount == 0) {
 break;
} else {
 start = rows.peekLast().getKey();

 if (lastEnd != null && Arrays.equals(start,lastEnd) ) { // modify this line
  break;
 }
 count += rowCount - 1;
 lastEnd = start;
}
  if (count > 0) {
   count += 1;
  }
  System.out.print("count de la tabla " + count);
  return count;
 }
change the UUID identify. Put byte[]

Thursday, October 25, 2012

Kundera not implement getCriteriaBuilder


I have cassandra intalled a computer.... I try create a template to make dinamics query with JPA. This is implemente.



    public <E extends Object> List<E> getAll(E e){
   
          CriteriaBuilder cb = em.getCriteriaBuilder();
         
          CriteriaQuery<E> q = cb.createQuery((Class<E>) e);
          Root<E> c = q.from((Class<E>) e);
          return (List<E>) q.select(c);
    }

But when I executed this progran throw a exception

NotImplementedException: TODO
    at com.impetus.kundera.persistence.EntityManagerFactoryImpl.getCriteriaBuilder(EntityManagerFactoryImpl.java:199)
    at com.impetus.kundera.persistence.EntityManagerImpl.getCriteriaBuilder(EntityManagerImpl.java:682)

Friday, October 19, 2012

cant find parent project

I have a maven project with module and parent proyect. If you launch a test module with command mvn  test this work, but you add a variable inside module that reference to parent proyect. ${project.version} and now launch mvn test, this fail. You must install project parent in your local repository to launch module.

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);

Wednesday, October 3, 2012

Neo4j + Sesame + OwlApi + Pellet


 To create inference in pellet and export this inferece to Neo4j with sail connector

function OpenSail 

        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);

function import ontology
  
     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.