オントロジーのインスタンスのデータ プロパティ値を表示しようとしています。私はこの目的のために Jena を使用しています。私のインスタンスは次のとおりです。
<!-- http://www.semanticweb.org/ontologies/2013/3/Ontology1365003423152.owl#Mailbomb -->
<NamedIndividual rdf:about="&Ontology1365003423152;Mailbomb">
<rdf:type rdf:resource="&Ontology1365003423152;Attack"/>
<Ontology1365003423152:HasService>smtp</Ontology1365003423152:HasService>
<Ontology1365003423152:HasFlag>SF</Ontology1365003423152:HasFlag>
<Ontology1365003423152:HasDuration>1</Ontology1365003423152:HasDuration>
<Ontology1365003423152:hasSrcBytes>2599</Ontology1365003423152:hasSrcBytes>
<Ontology1365003423152:HasType>Mailbomb</Ontology1365003423152:HasType>
<Ontology1365003423152:HasProtocol>tcp</Ontology1365003423152:HasProtocol>
<Ontology1365003423152:hasDestBytes>293</Ontology1365003423152:hasDestBytes>
</NamedIndividual>
<!-- http://www.semanticweb.org/ontologies/2013/3/Ontology1365003423152.owl#Smurf -->
<NamedIndividual rdf:about="&Ontology1365003423152;Smurf">
<rdf:type rdf:resource="&Ontology1365003423152;Attack"/>
<Ontology1365003423152:HasService>ecr_i</Ontology1365003423152:HasService>
<Ontology1365003423152:HasProtocol>icmp</Ontology1365003423152:HasProtocol>
<Ontology1365003423152:hasSrcBytes>1032</Ontology1365003423152:hasSrcBytes>
<Ontology1365003423152:HasFlag>SF</Ontology1365003423152:HasFlag>
<Ontology1365003423152:HasType>Smurf</Ontology1365003423152:HasType>
<Ontology1365003423152:hasDestBytes>0</Ontology1365003423152:hasDestBytes>
<Ontology1365003423152:HasDuration>0</Ontology1365003423152:HasDuration>
</NamedIndividual>
Jena を使用した Java での私のコードは次のとおりです。
public static void main(String[] args) {
String a[] = new String [7];
OntProperty p[] = new OntProperty [7];
OntModel inf = ModelFactory.createOntologyModel();
InputStream in = FileManager.get().open(inputFileName);
if (in == null) {
throw new IllegalArgumentException("File: " + inputFileName + " not found");
}
inf.read(in, "");
OntClass clas =inf.getOntClass("http://www.semanticweb.org/ontologies/2013/3/Ontology1365003423152.owl#Attack");
p[0] = inf.getOntProperty("HasProtocol");
p[1] = inf.getOntProperty("HasService");
p[2] = inf.getOntProperty("HasDuration");
p[3] = inf.getOntProperty("HasFlag");
p[4] = inf.getOntProperty("hasSrcBytes");
p[5] = inf.getOntProperty("hasDestBytes");
p[6] = inf.getOntProperty("HasType");
ExtendedIterator instances = clas.listInstances();
Individual instance = null;
while (instances.hasNext()) {
instance = (Individual) instances.next();
System.out.println(a[0] = instance.getPropertyValue(p[0]).toString());
System.out.println(a[1] = instance.getPropertyValue(p[1]).toString());
System.out.println(a[2] = instance.getPropertyValue(p[2]).toString());
System.out.println(a[3] = instance.getPropertyValue(p[3]).toString());
System.out.println(a[4] = instance.getPropertyValue(p[4]).toString());
System.out.println(a[5] = instance.getPropertyValue(p[5]).toString());
System.out.println(a[6] = instance.getPropertyValue(p[6]).toString());
}
}
これで、印刷の最初の反復ではゼロのみが印刷され、2 番目の反復では 293 のみが印刷されます (0 の 7 倍の後に 293 の 7 倍が続きます)。すべてに対して同じ値を取得しているため、何か間違っていると思います。私が見る方法は、各インスタンスの最後のデータ プロパティ値のみを出力することです。