我有这个 RDF 描述:
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:perSys="http://localhost:8080/NetworkContextWS/onto/NetworkContextDescription#">
<rdf:Description rdf:about="http://localhost:8080/NetworkContextWS/onto/NetworkContextDescription#PervasiveContext">
<perSys:HasNetworkContext>
<rdf:Description rdf:about="http://localhost:8080/NetworkContextWS/onto/NetworkContextDescription#NetworkContext">
<perSys:Rules>
<rdf:Description rdf:about="http://localhost:8080/NetworkContextWS/onto/NetworkContextDescription#NetworkSecurity">
<perSys:NetworkSecurityState rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>Open Network</perSys:NetworkSecurityState>
<perSys:NetworkKey rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>No Key</perSys:NetworkKey>
</rdf:Description>
</perSys:Rules>
<perSys:Network>
<rdf:Description rdf:about="http://localhost:8080/NetworkContextWS/onto/NetworkContextDescription#NetworkCharacteristics">
<perSys:SubNetworkType rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>HSDPA</perSys:SubNetworkType>
<perSys:NetworkState rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>CONNECTED</perSys:NetworkState>
<perSys:Bandwidth rdf:datatype="http://www.w3.org/2001/XMLSchema#float"
>450</perSys:Bandwidth>
<perSys:LinkSpeed rdf:datatype="http://www.w3.org/2001/XMLSchema#float"
>65</perSys:LinkSpeed>
<perSys:NetworkAvailability rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>Available</perSys:NetworkAvailability>
<perSys:NetworkName rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>AF23_WI-FI_9F1B</perSys:NetworkName>
</rdf:Description>
</perSys:Network>
<perSys:Network>
<rdf:Description rdf:about="http://localhost:8080/NetworkContextWS/onto/NetworkContextDescription#NetworkTraficStats">
<perSys:NumberBytesReceived rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>15599522</perSys:NumberBytesReceived>
<perSys:NumberPacketsReceived rdf:datatype="http://www.w3.org/2001/XMLSchema#int"
>24922</perSys:NumberPacketsReceived>
<perSys:NumberBytesTransmited rdf:datatype="http://www.w3.org/2001/XMLSchema#int"
>4111415</perSys:NumberBytesTransmited>
<perSys:NumberPacketsTransmited rdf:datatype="http://www.w3.org/2001/XMLSchema#int"
>26455</perSys:NumberPacketsTransmited>
<perSys:NetworkUpload rdf:datatype="http://www.w3.org/2001/XMLSchema#float"
>0</perSys:NetworkUpload>
<perSys:NetworkType rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>Connected</perSys:NetworkType>
<perSys:NetworkDownload rdf:datatype="http://www.w3.org/2001/XMLSchema#float"
>1</perSys:NetworkDownload>
<perSys:TotalData rdf:datatype="http://www.w3.org/2001/XMLSchema#float"
>1</perSys:TotalData>
</rdf:Description>
</perSys:Network>
<perSys:Time>
<rdf:Description rdf:about="http://localhost:8080/NetworkContextWS/onto/NetworkContextDescription#TimeCharacteristics">
<perSys:ConnexionTime rdf:datatype="http://www.w3.org/2001/XMLSchema#time"
>15:00:00</perSys:ConnexionTime>
<perSys:ConnexionDate rdf:datatype="http://www.w3.org/2001/XMLSchema#date"
>2015-02-06</perSys:ConnexionDate>
</rdf:Description>
</perSys:Time>
<perSys:Preferences>
<rdf:Description rdf:about="http://localhost:8080/NetworkContextWS/onto/NetworkContextDescription#PreferencesCharacteristics">
<perSys:PreferencesName rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>preferencesName</perSys:PreferencesName>
<perSys:PreferencesType rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>preferencesValue</perSys:PreferencesType>
</rdf:Description>
</perSys:Preferences>
<perSys:Device>
<rdf:Description rdf:about="http://localhost:8080/NetworkContextWS/onto/NetworkContextDescription#DeviceCharacteristics">
<perSys:DeviceName rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>Bekri-Laptop</perSys:DeviceName>
<perSys:DeviceType rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>Laptop</perSys:DeviceType>
</rdf:Description>
</perSys:Device>
<perSys:Location>
<rdf:Description rdf:about="http://localhost:8080/NetworkContextWS/onto/NetworkContextDescription#LocationCharacteristics">
<perSys:SpecificLocation rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>Gate 23</perSys:SpecificLocation>
<perSys:FeatureName rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>Pittsburgh International Airport</perSys:FeatureName>
</rdf:Description>
</perSys:Location>
</rdf:Description>
</perSys:HasNetworkContext>
<perSys:HasNetworkContext>
<rdf:Description rdf:about="http://localhost:8080/NetworkContextWS/onto/NetworkContextDescription#NetworkContext">
<perSys:Rules>
<rdf:Description rdf:about="http://localhost:8080/NetworkContextWS/onto/NetworkContextDescription#NetworkSecurity">
<perSys:NetworkSecurityState rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>Open Network</perSys:NetworkSecurityState>
<perSys:NetworkKey rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>No Key</perSys:NetworkKey>
</rdf:Description>
</perSys:Rules>
<perSys:Network>
<rdf:Description rdf:about="http://localhost:8080/NetworkContextWS/onto/NetworkContextDescription#NetworkCharacteristics">
<perSys:SubNetworkType rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>HSDPA</perSys:SubNetworkType>
<perSys:NetworkState rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>CONNECTED</perSys:NetworkState>
<perSys:Bandwidth rdf:datatype="http://www.w3.org/2001/XMLSchema#float"
>256</perSys:Bandwidth>
<perSys:LinkSpeed rdf:datatype="http://www.w3.org/2001/XMLSchema#float"
>65</perSys:LinkSpeed>
<perSys:NetworkAvailability rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>Available</perSys:NetworkAvailability>
<perSys:NetworkName rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>AF23_WI-FI_9F1B</perSys:NetworkName>
</rdf:Description>
</perSys:Network>
<perSys:Network>
<rdf:Description rdf:about="http://localhost:8080/NetworkContextWS/onto/NetworkContextDescription#NetworkTraficStats">
<perSys:NumberBytesReceived rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>15599522</perSys:NumberBytesReceived>
<perSys:NumberPacketsReceived rdf:datatype="http://www.w3.org/2001/XMLSchema#int"
>24922</perSys:NumberPacketsReceived>
<perSys:NumberBytesTransmited rdf:datatype="http://www.w3.org/2001/XMLSchema#int"
>4111415</perSys:NumberBytesTransmited>
<perSys:NumberPacketsTransmited rdf:datatype="http://www.w3.org/2001/XMLSchema#int"
>26455</perSys:NumberPacketsTransmited>
<perSys:NetworkUpload rdf:datatype="http://www.w3.org/2001/XMLSchema#float"
>0</perSys:NetworkUpload>
<perSys:NetworkType rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>Connected</perSys:NetworkType>
<perSys:NetworkDownload rdf:datatype="http://www.w3.org/2001/XMLSchema#float"
>1</perSys:NetworkDownload>
<perSys:TotalData rdf:datatype="http://www.w3.org/2001/XMLSchema#float"
>1</perSys:TotalData>
</rdf:Description>
</perSys:Network>
<perSys:Time>
<rdf:Description rdf:about="http://localhost:8080/NetworkContextWS/onto/NetworkContextDescription#TimeCharacteristics">
<perSys:ConnexionTime rdf:datatype="http://www.w3.org/2001/XMLSchema#time"
>15:00:00</perSys:ConnexionTime>
<perSys:ConnexionDate rdf:datatype="http://www.w3.org/2001/XMLSchema#date"
>2015-02-06</perSys:ConnexionDate>
</rdf:Description>
</perSys:Time>
<perSys:Preferences>
<rdf:Description rdf:about="http://localhost:8080/NetworkContextWS/onto/NetworkContextDescription#PreferencesCharacteristics">
<perSys:PreferencesName rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>preferencesName</perSys:PreferencesName>
<perSys:PreferencesType rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>preferencesValue</perSys:PreferencesType>
</rdf:Description>
</perSys:Preferences>
<perSys:Device>
<rdf:Description rdf:about="http://localhost:8080/NetworkContextWS/onto/NetworkContextDescription#DeviceCharacteristics">
<perSys:DeviceName rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>Bekri-Laptop</perSys:DeviceName>
<perSys:DeviceType rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>Laptop</perSys:DeviceType>
</rdf:Description>
</perSys:Device>
<perSys:Location>
<rdf:Description rdf:about="http://localhost:8080/NetworkContextWS/onto/NetworkContextDescription#LocationCharacteristics">
<perSys:SpecificLocation rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>Gate 15</perSys:SpecificLocation>
<perSys:FeatureName rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>Pittsburgh International Airport</perSys:FeatureName>
</rdf:Description>
</perSys:Location>
</rdf:Description>
</perSys:HasNetworkContext>
</rdf:Description>
</rdf:RDF>
我想应用 Jena 规则来选择带宽值等于 450 的位置。我创建了这个规则:
@prefix rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns#
@prefix xs: http://www.w3.org/2001/XMLSchema#
@prefix perSys http://localhost:8080/NetworkContextWS/onto/NetworkContextDescription#
[AdaptedModel:
(?a ?rdf:type ?t2),
(?b ?rdf:type ?t3),
(?c ?rdf:type ?t4),
(?gh perSys:Bandwidth '450'^^xsd:float)
(?klx perSys:SpecificLocation ?jkl)
->
(?klx perSys:AdaptedSpecificLocation ?jkl)]
响应通常是:
<perSys:AdaptedSpecificLocation rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Gate 15</perSys:AdaptedSpecificLocation>
但引擎响应是:
<perSys:AdaptedSpecificLocation rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Gate 15</perSys:AdaptedSpecificLocation>
<perSys:AdaptedSpecificLocation rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Gate 23</perSys:AdaptedSpecificLocation>
引擎java源是:
public void runEngine(String ruleFile, String rdfFile) {
String net = "http://localhost:8080/NetworkContextWS/onto/NetworkContextDescription#";
model = ModelFactory.createDefaultModel();
java.io.InputStream inschema =FileManager.get().open(rdfFile);
model.read(inschema, net);
java.util.List rules1 = Rule.rulesFromURL(ruleFile);
System.out.println(rules1);
Reasoner reasoner = new GenericRuleReasoner(rules1);
reasoner = reasoner.bindSchema(model);
InfModel infmodel = ModelFactory.createInfModel(reasoner,model);
Resource children = infmodel.getResource(net+"SpecificLocation");
infmodel.write(System.out, "RDF/XML-ABBREV");
}
谢谢你回复我。