Corese 3.0 / KGRAM Goodies

olivier.corby at inria.fr - Edelweiss - INRIA Sophia Antipolis-Méditerranée - 2009-2011.

Mode

select debug   # debug mode
select more    # approximate search
select check   # type check

Functions

Semantic similarity for approximate search

select (kg:similarity() as ?sim)  
Semantic similarity between classes
kg:similarity(?c1, ?c2)  
Contain Word Ignore Case And Accent
kg:contains(?text, 'Elégant')
Equal Word Ignore Case And Accent
kg:equal(?text, 'Elégant')

XPath

Mashup of XML data.

select * where {
  graph ?g { <John> foaf:knows ?y }
  {select (xpath(?g, '//foaf:name') as ?name) where {}}
}

SQL

Mashup of relational data.

prefix db: <jdbc:mysql://localhost/>
prefix dr: <com.mysql.jdbc.>

construct {
  ?s foaf:knows ?o
}
where {
  select 
    (sql(db:dbase, dr:Driver, 'username', 'password', 
     'select A, B from C where D') 
    as (?x, ?y)) where {} .
  
  {select (uri(?x) as ?s) (uri(?y) as ?o) where {}}
}

XSLT & SPARQL

XSLT with embedded SPARQL Query with KGRAM/KGRAPH. Thanx to Fabien Gandon.

public static XSLTQuery create(String xsl, QuerySolver exec);

public String xslt(String doc);
<xsl:stylesheet

xmlns:xalan="http://xml.apache.org/xalan"
xmlns:server="xalan://fr.inria.edelweiss.kgtool.print.XSLTQuery"

extension-element-prefixes="server"
/>

<xsl:param name='engine' />


<xsl:variable name='query1'>
select * where {?x c:FirstName 'John'}
</xsl:variable> 

<xsl:variable name='query2'>
construct {?x c:name 'John'} 
where {?x c:FirstName 'John'}
</xsl:variable> 

<xsl:variable name='res1'  select='server:sparql($engine, $query1)' />

<xsl:variable name='res2'  select='server:sparql($engine, $query2)' />

Pipeline

Pipe p = Pipe.create(graph);
p.process("pipe.rdf");
<rdf:RDF  xmlns='http://ns.inria.fr/edelweiss/2010/kgram/'>
<Pipeline>
   <body rdf:parseType='Collection'>
     <Load   rdf:about = 'onto.rdfs' />
     <Load   rdf:about = 'data.rdf' />
     <Update rdf:about = 'query.rq'/>
     <Rule   rdf:about = 'rule.rq'/>
     <RuleBase   rdf:about = 'base.rul'/>
     <RuleBase>
        <body rdf:parseType='Collection'>
           <Rule rdf:about = 'rule1.rq'/>
           <Rule rdf:about = 'rule2.rq'/>
        </body>
     </RuleBase>
     <Pipeline rdf:about = 'pipe.rdf' />
   </body>
</Pipeline>
</rdf:RDF>