Cosmas; Others may have more specific help in terms of the SPIN API, but one thought is whether you are importing the SPIN library when trying to execute the inference?  Chances are, there is a missing file - and one way to to find it is to look at your model in Composer.  Make sure all of the files used in Composer to run the rule successfully are present in your Java code.

Also I couldn't help but look at your Java (not JSP) code and present the much simpler and more maintainable SWP syntax as something to consider. This takes 2 objects because I decided to place the SPARQL in a template as opposed to embedding it in the tags.

subclass of spin:SelectTemplate named :PriceType:

SELECT ?a ?b
WHERE {
  ?s :resto_name ?a .
  ?s :price_type ?b .
}

subclass of ui:Element named :displayTable:

<ui:call ui:template=":
PriceType">
   Found {= spr:rowCount(?rs) } triples
   <br/>This is the data <br/>
   <table border='1'>
      <ui:forEach ui:resultSet="{= ?rs }">
         <tr><td>{= ?a }</td>
            <td>
{= ?b }</td></tr>
      </ui:forEach>
   </table>
</ui:call>

Note how, as is done in JSP etc., the HTML/XML (any text really) is defined directly with processing directives ( {= } ) embedded in the text.  And since this snippet is named, it becomes a custom tag, <:displayTable/>, that can be used anywhere in other XML snippets or called as a Web service.  I.e. the above creates a custom tag and custom tags are defined using SPARQL/XHTML/_javascript_ all the way down.

For more on SWP take a look at these links:
  - http://uispin.org/
  - http://www.topquadrant.com/swp/
  - Composer Help at opBraid Composer > Developing Semantic Web Applications > SPARQL Web Pages Overview

Again, just something to consider...

-- Scott

On 3/8/2013 2:48 AM, cosmas haryawan wrote:
Dear all,
I have an owl file with name resto.owl, and created a simple rule using construct like this :
CONSTRUCT {
    ?s :price_type ?p .
}
WHERE {
    ?s :highest_price ?h .
    BIND (IF((?h > 3000), "EXPENSIVE", "CHEAP") AS ?p) .
}


Using TBC, I have run a simple sparql in SPARQL editor:
SELECT ?a ?b
WHERE {
  ?s :resto_name ?a .
  ?s :price_type ?b .
}

All worked perfect!

The problem is,
 when I executed the same sparql using SPIN API, I got the right newTriples size but with no result in Sparql query.
Any help or hint will be appreciated.
Thanks.
This is my JSP script :

        SPINModuleRegistry.get().init();
        Model baseModel = ModelFactory.createDefaultModel(ReificationStyle.Minimal);
        baseModel.read("http://localhost/resto.owl");
        String vResult = "";
        String query = "";

        // Create OntModel with imports
        OntModel _ontModel_ = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, baseModel);
        // Create and add Model for inferred triples
        Model newTriples = ModelFactory.createDefaultModel(ReificationStyle.Minimal);
        ontModel.addSubModel(newTriples);
        // Register locally defined functions
        SPINModuleRegistry.get().registerAll(ontModel, null);
        // Run all inferences
        SPINInferences.run(ontModel, newTriples, null, null, false, null);

        vResult = " Found : " + String.valueOf(newTriples.size()) + " triples <br/> "
                + "This is the data <br/><table border='1'>";

        query = ""
                + "   select ?a ?b  "
                + " where { "
                + " ?s :resto_name ?a . "
                + " ?s :price_type ?b . "
                + " } ";

        Query arqQuery = ARQFactory.get().createQuery(baseModel, query);
        QueryExecution qexec = ARQFactory.get().createQueryExecution(arqQuery, baseModel);
        try {
            ResultSet rs = qexec.execSelect();
            for (; rs.hasNext();) {
                QuerySolution qs = rs.nextSolution();
                vResult += "<tr><td> "+ qs.getLiteral("a").getValue().toString() + "</td>";
                vResult += "<td> "+ qs.getLiteral("b").getValue().toString() + "</td>";
                vResult += "</tr>";
            }
            vResult += "</table>";
        } finally {
            qexec.close();
        }


--
-- You received this message because you are subscribed to the Google
Group "TopBraid Suite Users", the topics of which include Enterprise Vocabulary Network (EVN), TopBraid Composer, TopBraid Live,
TopBraid Ensemble, SPARQLMotion, SPARQL Web Pages and SPIN.
To post to this group, send email to
[email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/topbraid-users?hl=en
---
You received this message because you are subscribed to the Google Groups "TopBraid Suite Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.
 
 

--
-- You received this message because you are subscribed to the Google
Group "TopBraid Suite Users", the topics of which include Enterprise Vocabulary Network (EVN), TopBraid Composer, TopBraid Live,
TopBraid Ensemble, SPARQLMotion, SPARQL Web Pages and SPIN.
To post to this group, send email to
[email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/topbraid-users?hl=en
---
You received this message because you are subscribed to the Google Groups "TopBraid Suite Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply via email to