Hi All, 1) I've annotated with success all my entities with standard features "original name", "class", "instance", "rule", etc.; but if I want also to show other features that I've correctly put in file .nt consistent with the file. owl, like descriptions (view DatatypeProperty hasDescription in my files in.space.owl and in.space.nt), how can I do? Is it possible? Give me some advice...
2) attached there is a copy of code http://www.ontotext.com/kim/doc/sys- doc/ExploreEntitiesExamples.html but it seems there is an inconsistency: where is the declaration of "entCount"? which is the path of libraries for BNodeImpl, URIImpl, EntityQueryResult, Resource? Please, give me a right to run this program... Greetings, Valentina
/*
* To view the entities for a document and their properties the document has to
be
* annotated first. For every document annotation the 'inst' feature gives an
URI
* to a resource holding an entity. The example below uses a SeRQL query to get
the
* main label of each entity, it counts how many times the current entity
occurred
* in the annotated document and fills a map with labels and counts that is
viewed
* at the end of the example.
* */
import com.ontotext.kim.client.KIMService;
import com.ontotext.kim.client.GetService;
import com.ontotext.kim.client.corpora.CorporaAPI;
import com.ontotext.kim.client.documentrepository.DocumentRepositoryAPI;
import com.ontotext.kim.client.semanticannotation.SemanticAnnotationAPI;
import com.ontotext.kim.client.query.QueryAPI;
import com.ontotext.kim.client.semanticrepository.SemanticRepositoryAPI;
import com.ontotext.kim.client.coredb.CoreDbAPI;
import com.ontotext.kim.client.corpora.KIMDocument;
import com.ontotext.kim.client.corpora.KIMFeatureMap;
import com.ontotext.kim.client.corpora.KIMFeatureMapImpl;
import com.ontotext.kim.client.corpora.KIMAnnotation;
import com.ontotext.kim.client.corpora.KIMAnnotationSet;
import com.ontotext.kim.client.corpora.KIMCorporaException;
import com.ontotext.kim.client.model.FeatureConstants;
import java.net.URL;
import java.util.Iterator;
import java.util.Set;
import java.util.List;
import java.util.HashSet;
import java.util.Vector;
import java.io.*;
public class DocTest2 {
public static final String RMI_HOST= "localhost";
public static final int RMI_PORT= 1099;
public static final String start= "<?xml version=\"1.0\"
encoding=\"UTF-8\"?>";
public static void main(String[] args) {
try {
// connessione al KIMservice
//KIMService serviceKim= GetService.from(RMI_HOST, RMI_PORT);
KIMService serviceKim= GetService.from();
System.out.println("KIM Server connesso.");
// otteniamo componenti CorporaAPI e SemanticAnnotationAPI
CorporaAPI apiCorpora= serviceKim.getCorporaAPI();
System.out.println("CorporaAPI ottenuto con successo.");
SemanticAnnotationAPI apiSemAnn= serviceKim.getSemanticAnnotationAPI();
System.out.println("SemanticAnnotationAPI ottenuto con successo.");
// DocumentRepositoryAPI apiDR = serviceKim.getDocumentRepositoryAPI();
// spit("DocumentRepositoryAPI ottenuto con successo.");
// QueryAPI apiQuery = serviceKim.getQueryAPI();
// spit("QueryAPI ottenuto con successo.");
SemanticRepositoryAPI apiSesame =
serviceKim.getSemanticRepositoryAPI();
System.out.println("SemanticRepositoryAPI ottenuto con successo.");
// CoreDbAPI apiCoreDb = serviceKim.getCoreDbAPI();
// spit("CoreDbAPI ottenuto con successo.");
// create and annotate document
URL url2= new URL ("http://www.ontotext.com/kim");
KIMDocument kdoc= apiCorpora.createDocument(url2, "UTF-8");
apiSemAnn.execute(kdoc);
// view document's entities
KIMAnnotationSet kimASet= kdoc.getAnnotations();
Iterator annIterator= kimASet.iterator();
System.out.println("--> Entità del documento...");
while( annIterator.hasNext()) {
// get annotation and annotations features
KIMAnnotation kimAnnotation = (KIMAnnotation)
annIterator.next();
KIMFeatureMap kimFeatures = kimAnnotation.getFeatures();
if(kimFeatures != null) {
String resourceUri = (String)
kimFeatures.get(FeatureConstants.INSTANCE);
Resource uriRes = null;
if(resourceUri.startsWith("_")) {
// anonymous resource
uriRes= new BNodeImpl(resourceUri);
}
else {
uriRes= new URIImpl(resourceUri);
}
// get the labels of the entities
EntityQueryResult properties=
apiSesame.evaluateSelectSeRQL("select distinct MainLabel "
+ "from {<" + uriRes.toString() + ">} <" +
URIImpl.RDFS_LABEL.getURI()
+ "> {MainLabel}");
// count entities and fill a map with number and names
while(properties.hasNext()){
String curLabel = ((List)
properties.next()).get(0).toString();
if(entCount.containsKey(curLabel)){
Long prev= (Long) entCount.get(curLabel);
entCount.put(curLabel, new Long
(prev.longValue()+1));
}else {
entCount.put(curLabel, new Long(1));
}
}
}
}
// view entities with count and name
Iterator cntIterator= entCount.keySet().iterator();
while(cntIterator.hasNext()) {
String entLabel= cntIterator.next().toString();
long entOccurs= ((Long ) entCount.get(entLabel)).longValue();
System.out.println("num: " + entOccurs + "\t\t name: " + entLabel);
}
System.out.println("\n");
} catch (Exception e) {e.printStackTrace();}
}
}<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE owl [
<!ENTITY rdf 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
<!ENTITY rdfs 'http://www.w3.org/2000/01/rdf-schema#'>
<!ENTITY owl 'http://www.w3.org/2002/07/owl#' >
<!ENTITY xsd 'http://www.w3.org/2001/XMLSchema#' >
<!ENTITY psys 'http://proton.semanticweb.org/2006/05/protons#'>
<!ENTITY ptop 'http://proton.semanticweb.org/2006/05/protont#'>
<!ENTITY protonkm 'http://proton.semanticweb.org/2006/05/protonkm#'>
]>
<rdf:RDF
xmlns:owl="&owl;"
xmlns:rdf="&rdf;"
xmlns:rdfs="&rdfs;"
xmlns:psys="&psys;"
xmlns:ptop="&ptop;"
xmlns:protonkm="&protonkm;"
xmlns="http://in.space#"
xml:base="http://in.space#">
<owl:AnnotationProperty rdf:about="http://www.w3.org/2000/01/rdf-schema#comment"/>
<owl:AnnotationProperty rdf:about="http://www.w3.org/2000/01/rdf-schema#label"/>
<owl:AnnotationProperty rdf:about="http://www.w3.org/2002/07/owl#versionInfo"/>
<owl:Ontology rdf:about="">
<rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">InSpac</rdfs:label>
<rdfs:comment>InSpace Ontolog</rdfs:comment>
<owl:imports rdf:resource="http://proton.semanticweb.org/2006/05/protons"/>
<owl:versionInfo>"0.11"</owl:versionInfo>
</owl:Ontology>
<owl:Class rdf:ID="SongTitle">
<rdfs:label>SongTitle</rdfs:label>
<rdfs:comment>
A short musical composition with words.
</rdfs:comment>
<rdfs:subClassOf rdf:resource="&psys;Entity"/>
</owl:Class>
<owl:Class rdf:ID="Singer">
<rdfs:label>Singer</rdfs:label>
<rdfs:comment>
A person who sings.
</rdfs:comment>
<rdfs:subClassOf rdf:resource="&psys;Entity"/>
</owl:Class>
<owl:Class rdf:ID="MusicGenre">
<rdfs:label>MusicGenre</rdfs:label>
<rdfs:comment>
An expressive style of music
</rdfs:comment>
<rdfs:subClassOf rdf:resource="&psys;Entity"/>
</owl:Class>
<owl:DatatypeProperty rdf:about="#hasDescription"
rdfs:label="has Description">
<rdfs:comment></rdfs:comment>
<rdfs:domain rdf:resource="#MusicGenre"/>
</owl:DatatypeProperty>
<owl:ObjectProperty rdf:about="#createdBy" rdfs:label="sungBy">
<rdfs:domain rdf:resource="#Song"/>
<rdfs:range rdf:resource="&psys;Entity"/>
</owl:ObjectProperty>
<owl:ObjectProperty rdf:about="#createdBy" rdfs:label="typeOf">
<rdfs:domain rdf:resource="#Song"/>
<rdfs:range rdf:resource="&psys;Entity"/>
</owl:ObjectProperty>
</rdf:RDF>
in.space.nt
Description: Binary data
_______________________________________________ Kim-discussion mailing list [email protected] http://ontotext.com/mailman/listinfo/kim-discussion
