openlink / virtuoso-opensource

Virtuoso is a high-performance and scalable Multi-Model RDBMS, Data Integration Middleware, Linked Data Deployment, and HTTP Application Server Platform
https://vos.openlinksw.com
Other
866 stars 210 forks source link

Issue in using bif:__rdf_long_from_batch_params in bif:contains #525

Open nishit26 opened 8 years ago

nishit26 commented 8 years ago

I am trying to pass search string dynamically in bif:contains function as entered by the user and then search the pattern in DBPedia to get the result. But it is not working at all. The code & stack trace are mentioned in below. Thanks in advance for the help.

String sql = "sparql PREFIX db: http://dbpedia.org/resource/ PREFIX owl: http://www.w3.org/2002/07/owl# select ?subject, ?label WHERE {?subject rdfs:label ?label . Filter(bif:contains(?label, \"bif:__rdf_long_from_batch_params(??,??,??)\")) .} limit 5";

    final Value rdfEntityValue = factory.createLiteral(entityName);             
    List<DBPediaCategory> lstEntityCategories = getVirtuosoJdbcTemplate().query(sql, new PreparedStatementSetter() {            
        public void setValues(PreparedStatement pstmt) throws SQLException {
            bindValue(pstmt, 1, rdfEntityValue);
            //bindValue(pstmt, 2, rdfEntityValue);
        }
    }, new ResultSetExtractor<List<DBPediaCategory>>() { 
        public List<DBPediaCategory> extractData(ResultSet rs) throws SQLException, DataAccessException {
            List<DBPediaCategory> lstEntityCategories = new ArrayList<DBPediaCategory>();
            while(rs.next()){
                DBPediaCategory cat= new DBPediaCategory();
                cat.setSubject(rs.getString("subject"));
                cat.setDbpediaType(rs.getString("type"));
                cat.setDbpediaParentType(rs.getString("ptype"));cat.setSubject(rs.getString(1));
                lstEntityCategories.add(cat);
            }
            return lstEntityCategories;
        }
    });

Trace is as follows

Exception in thread "main" org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [sparql PREFIX db: http://dbpedia.org/resource/ PREFIX owl: http://www.w3.org/2002/07/owl# select ?subject, ?label WHERE {?subject rdfs:label ?label . Filter(bif:contains(?label, "bif:__rdf_long_from_batch_params(??,??,??)")) .} limit 5]; nested exception is virtuoso.jdbc4.VirtuosoException: Index 1 is not 1<n<0 at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:98) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:603) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:637) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:666) at test.web.dao.impl.DbpediaDAOImpl.getDBPediaCategoryForEntity(DbpediaDAOImpl.java:53) at com.news.teststub.TestStub.main(TestStub.java:35) Caused by: virtuoso.jdbc4.VirtuosoException: Index 1 is not 1<n<0 at virtuoso.jdbc4.VirtuosoPreparedStatement.setInt(VirtuosoPreparedStatement.java:412) at test.web.dao.impl.DbpediaDAOImpl.bindValue(DbpediaDAOImpl.java:139) at test.web.dao.impl.DbpediaDAOImpl.access$0(DbpediaDAOImpl.java:119) at test.web.dao.impl.DbpediaDAOImpl$1.setValues(DbpediaDAOImpl.java:55) at org.springframework.jdbc.core.JdbcTemplate$1.doInPreparedStatement(JdbcTemplate.java:642) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:587) ... 4 more

smalinin commented 8 years ago

Try to use the next syntax

`bif:__rdf_long_from_batch_params(??,??,??)`

instead of

\"bif:__rdf_long_from_batch_params(??,??,??)\"
nishit26 commented 8 years ago

Thanks for the response. I have tried the same as you have mentioned. But this gibes below exception.

PreparedStatementCallback; bad SQL grammar [sparql PREFIX db: http://dbpedia.org/resource/ PREFIX owl: http://www.w3.org/2002/07/owl# select ?subject, ?label WHERE {?subject rdfs:label ?label . Filter(bif:contains(?label, bif:__rdf_long_from_batch_params(??,??,??))) .} limit 5]; nested exception is virtuoso.jdbc4.VirtuosoException: SQ074: Line 1: SP030: SPARQL compiler, line 1: syntax error at '`' before 'bif:__rdf_long_from_batch_params'

Caused by: virtuoso.jdbc4.VirtuosoException: SQ074: Line 1: SP030: SPARQL compiler, line 1: syntax error at '`' before 'bif:__rdf_long_from_batch_params'