Add a property restriction, using an anonymous class, using Apache Jena - owl

I am trying to add the following fragment to a .owl file that I create in Prótegé:
<owl: Class rdf: about = "http://www.semanticweb.org/example/ontologies/2021/8/test#subs_de_sp3">
<owl: equivalentClass>
<owl: Class>
<owl: intersectionOf rdf: parseType = "Collection">
<rdf: Description rdf: about = "http://www.semanticweb.org/example/ontologies/2021/8/test#subsymptom" />
<owl: Restriction>
<owl: onProperty rdf: resource = "http://www.semanticweb.org/example/ontologies/2021/8/test#is_symptom_of" />
<owl: hasValue rdf: resource = "http://www.semanticweb.org/example/ontologies/2021/8/test#sp3" />
</ owl: Restriction>
</ owl: intersectionOf>
</ owl: Class>
</ owl: equivalentClass>
</ owl: Class>
I have read https://jena.apache.org/documentation/ontology/ but cannot complete the task. I have come this far:
public static void main (String [] args) {
OntModel model = ModelFactory.createOntologyModel (OntModelSpec.OWL_MEM_RULE_INF, null);
InputStream ontologyIn = FileManager.get (). Open ("~ / jena_example / ontologies / symptom_rdf.owl");
model.read (ontologyIn, "RDF / XML");
OntClass anon class = model.createClass ();
OntClass class = model.getOntClass (NS + "subsymptom");
class.addEquivalentClass (classanon);
How can I complete the task? I would appreciate any help.
Thanks in advance

Related

SPARQL - How to get only newest entities

In my triple store i've a collection of schema:CreativeWork which has the property schema:version and schema:dateCreated.
Now i want to get all schema:CreativeWork but only the newest ones.
My sample:
PREFIX schema: <https://schema.org/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT DISTINCT *
WHERE {
?subject rdf:type schema:CreativeWork .
?subject schema:identifier ?identifier .
?subject schema:version ?version .
?subject schema:dateCreated ?dateCreated .
OPTIONAL {?subject schema:about/schema:name ?name .}
FILTER( ?identifier = "46d8b7abfec44865a567ea04e385661b" ) .
} LIMIT 10
How do i manage to query only the latest version?
executable sample: https://api.triplydb.com/s/rLq4V-JgS
Note: FILTER( ?identifier = "46d8b7abfec44865a567ea04e385661b" ) . is just to make it easier.
The query of UninformedUser is working well:
PREFIX schema: <https://schema.org/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT DISTINCT *
{
{
SELECT ?identifier (max(?dateCreated) as ?latestDate)
WHERE {
?subject rdf:type schema:CreativeWork .
?subject schema:identifier ?identifier .
?subject schema:dateCreated ?dateCreated .
} group by ?identifier
}
?subject schema:identifier ?identifier .
?subject schema:version ?version .
?subject schema:dateCreated ?latestDate .
OPTIONAL {?subject schema:about/schema:name ?name . }
} LIMIT 100

How To Implement Full Search in Case Type using Salesforce?

I need to build out a solution to create a search field on the new Case Type Data object in all 3 of the Level fields and populate based on selection.
Similar to SF Global Search I would like to type 2-3 characters in the text search field and it would find the matching text in the Level1-3 fields and when selected the Level 1-3 field would populate.
This is the apex class
public class PickListHandler {
#AuraEnabled
public static List<String> getLevel1(){
List<String> tempLst1 = new List<String>();
for(AggregateResult ar : [select Level_1__c,COUNT(id) from Case_Type_Data__c group by Level_1__c])
{
tempLst1.add(''+ar.get('Level_1__c'));
}
return tempLst1;
}
#AuraEnabled
public static List<String> getLevel2(string strName){
List<String> tempLst2 = new List<String>();
for(AggregateResult ar : [select Level_2__c,COUNT(id) from Case_Type_Data__c where Level_1__c=:strName group by Level_2__c])
{
tempLst2.add(''+ar.get('Level_2__c'));
}
return tempLst2;
}
#AuraEnabled
public static List<String> getLevel3(string strName1,string strName2){
List<String> tempLst3 = new List<String>();
for(AggregateResult ar : [select Level_3__c,COUNT(id) from Case_Type_Data__c where Level_1__c=:strName1 and Level_2__c=:strName2 group by Level_3__c])
{
tempLst3.add(''+ar.get('Level_3__c'));
}
return tempLst3;
}
#AuraEnabled
public static String savecasetype(string level1,string level2,string level3,string id){
string strMsg='successfull';
try{
ERT_Case_Type__c obj=new ERT_Case_Type__c();
Obj.Case__c = id;
System.debug('CASE = '+ Obj.Case__c);
Obj.Level_1__c=level1;
System.debug('Level1 = '+ Obj.Level_1__c);
Obj.Level_2__c=level2;
System.debug('Level2 = '+ Obj.Level_2__c);
Obj.Level_3__c=level3;
System.debug('Level3 = '+ Obj.Level_3__c);
Insert obj;
}
catch(Exception ex){
strMsg='error';
}
return strMsg;
}
}
This is the Picklist handler component
<aura:component controller="PickListHandler" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
<!-- Actions-->
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<!-- variable-->
<aura:attribute name="lstLevel1" type="String[]" />
<aura:attribute name="lstLevel2" type="String[]" />
<aura:attribute name="lstL3" type="String[]" />
<span> Level 1</span>
<ui:inputSelect aura:id="ddLevel1" change="{!c.getLvl1}">
<ui:inputSelectOption label="-Select-" value="true"/>
<aura:iteration items="{!v.lstLevel1}" var="value">
<ui:inputSelectOption label="{!value}" text="{!value}" />
</aura:iteration>
</ui:inputSelect>
<span>Level 2</span>
<ui:inputSelect aura:id="ddLevel2" change="{!c.getSelectedValue}">
<ui:inputSelectOption label="-Select-" value="true"/>
<aura:iteration items="{!v.lstLevel2}" var="value">
<ui:inputSelectOption label="{!value}" text="{!value}" />
</aura:iteration>
</ui:inputSelect>
<span>Level 3</span>
<ui:inputSelect aura:id="ddLevel3" >
<ui:inputSelectOption label="-Select-" value="true"/>
<aura:iteration items="{!v.lstL3}" var="value">
<ui:inputSelectOption label="{!value}" text="{!value}" />
</aura:iteration>
</ui:inputSelect>
<lightning:button variant="brand" label="Save" onclick="{!c.onConfirm}" />
</aura:component>
Regards,
Carolyn
You're asking for a lot, we wouldn't have your custom object. And this is old code, ui:inputSelect is deprecated for 1 year now. I'll try to help a bit but the whole thing needs your work too. And examples we can reproduce easily.
I'm going to cheat and use Philippe Ozil's ready component for the lookup/autocomplete thing.
It means you'd have to save LookupSearchResult class, the whole aura component and 2 aura events in your org before reading below. That's some prep work but it's battle-tested :)
Apex class
public with sharing class Stack64129038 {
#AuraEnabled(cacheable=true)
public static List<LookupSearchResult> search(String searchTerm, List<String> selectedIds){
if(String.isBlank(searchTerm) || searchTerm.length() < 2){
return null;
}
String t = '%' + searchTerm + '%'; // decide how you want to search, "starts with", "includes" or what
List<Case_Type_Data__c> records = [SELECT Id, Name, Level_1__c, Level_2__c, Level_3__c
FROM Case_Type_Data__c
WHERE Level_1__c LIKE :t OR Level_2__c LIKE :t OR Level_3__c LIKE :t
ORDER BY Level_1__c, Level_2__c, Level_3__c
LIMIT 20];
/* You could also experiment with SOSL?
records = [FIND :('*' + searchTerm + '*') IN ALL FIELDS
RETURNING Case_Type_Data__c(Id, Name, Level_1__c, Level_2__c, Level_3__c)][0];
*/
List<LookupSearchResult> results = new List<LookupSearchResult>();
for(Case_Type_Data__c ctd : records){
results.add(new LookupSearchResult(ctd.Id, 'Case_Type_Data__c', 'standard:case_wrap_up', ctd.Name,
String.join(new List<String>{ctd.Level_1__c , ctd.Level_2__c, ctd.Level_3__c}, '; ')
));
}
return results;
}
}
Aura component (html part)
<aura:component implements="force:hasRecordId,force:appHostable,flexipage:availableForAllPageTypes,force:lightningQuickAction" access="global" controller="Stack64129038">
<aura:attribute access="private" type="List" name="selection" default="[]"/>
<aura:attribute access="private" type="List" name="errors" default="[]"/>
<lightning:card title="New Case Type">
<lightning:recordEditForm aura:id="myForm" objectApiName="ERT_Case_Type__c" onsubmit="{!c.onSubmit}" onsuccess="{!c.onSuccess}">
<lightning:messages />
<c:Lookup selection="{!v.selection}" onSearch="{!c.lookupSearch}" onSelection="{!c.useSelected}" errors="{!v.errors}" label="Search" placeholder="Search Case Types Data"/>
<lightning:inputField aura:id="Level_1__c" fieldName="Level_1__c" />
<lightning:inputField aura:id="Level_2__c" fieldName="Level_2__c" />
<lightning:inputField aura:id="Level_3__c" fieldName="Level_3__c" />
<lightning:button class="slds-m-top_small" variant="brand" type="submit" name="save" label="Save" />
</lightning:recordEditForm>
</lightning:card>
</aura:component>
Aura component - JS controller part
({
lookupSearch : function(component, event, helper) {
// Get the lookup component that fired the search event
const lookupComponent = event.getSource();
const serverSearchAction = component.get('c.search');
lookupComponent.search(serverSearchAction);
},
useSelected: function(component, event, helper) {
const selection = component.get('v.selection');
const errors = component.get('v.errors');
if (selection.length) {
if(errors.length){ // Clear errors, if any
component.set('v.errors', []);
}
let levels = selection[0].subtitle.split('; ');
component.find('Level_1__c').set('v.value', levels[0]);
component.find('Level_2__c').set('v.value', levels[1]);
component.find('Level_3__c').set('v.value', levels[2]);
}
},
onSubmit: function(component, event, helper) {
debugger;
event.preventDefault(); // stop the form from submitting
var fields = event.getParam('fields');
fields.Case__c = component.get('v.recordId'); // link to "this" Case
component.find('myForm').submit(fields);
},
onSuccess: function(component, event, helper){
var toastEvent = $A.get("e.force:showToast");
toastEvent.setParams({
"title": "Success!",
"message": "Case Type saved OK, refreshing",
"type": "success"
});
toastEvent.fire();
$A.get('e.force:refreshView').fire(); // reload page
}
})

SWRLb - greaterThan and lessThan triggered

I have a problem using SWRL rules. I have a robot that should notify a human in case of two abnormal situations. For my test case I use the tension of a user:
if the tension is less than 14, then the robot alert that the tension is low:
(:hasTension :Charles ?x) &wedge; greaterThan(?x, "14.0"^^xsd:float) &rightarrow; (:hasAlert :Samii "Your tension is high"^^xsd::string)
if the tension is greater than 14, the robot alert that the tension is high.
(:hasTension :Charles ?x) &wedge; lessThan(?x, "14.0"^^xsd:float) &rightarrow; (:hasAlert :Samii "Your tension is low"^^xsd::string)
I am Using OWL API with pellet reasoner (openllet fork of pellet). To do so I have my SWRL rules using builtin swrlb:greaterThan and swrlb:lessThan. For the test I add the axiom
:Charles :hasTension "10"^^xsd:float
and query the data property
:Samii :hasAlert ?alert
But when I query the ontology, I get two alerts: one for greaterThan and the other for lessThan. I think my rules are well formed, and I don't have any warning or error from the API saying the builtin are not implemented, so I believe that the rules should work as I'd expect. Any idea why I'm getting the unexpected alert?
Resources
My test "main"
package com.samii.restful;
import java.util.ArrayList;
import org.apache.jena.rdf.model.Statement;
public class Local {
public static void main(String[] args)
{
String path = ""+ Servlet.class.getResource("/Ontologies/justAtest_RDFXML.owl");
Local.mainPelletOWLAPI(path);
}
public static void mainPelletOWLAPI( String path ){
OWLManagement owl_management = new OWLManagement( path );
System.out.println( "[main].main => \n\n== Before adding axiom ==" );
owl_management.printOntology();
System.out.println( "[main].main => \n\n== Query ==" );
String URI = "file:///C:/Users/cclercq/.eclipse/ws_Samii/Samii/WebContent/Ontologies/justAtest_RDFXML#";
String ssubject = "Samii";
String spredicate = "hasAlert";
ArrayList<Object> literals = owl_management.queryDataProperty(URI, ssubject, spredicate);
System.out.println("[main].main() -> Number of literals: " + literals.size() );
if( !literals.isEmpty() ){
for( Object literal : literals){
System.out.print( "->" + ssubject + " " + spredicate + " " + literal );
}
}
ssubject = "Charles";
spredicate = "hasTension";
String sobject = "10";
owl_management.updateFunctionalObjectsProperty(URI, ssubject, spredicate, sobject, "float");
System.out.println( "[main].main => \n\n== After adding axiom ==" );
owl_management.printOntology();
System.out.println( "[main].main => \n\n== Query ==" );
ssubject = "Samii";
spredicate = "hasAlert";
literals = owl_management.queryDataProperty(URI, ssubject, spredicate);
System.out.println("[main].main() -> Number of literals: " + literals.size() );
if( !literals.isEmpty() ){
for( Object literal : literals){
System.out.println( "->" + ssubject + " " + spredicate + " " + literal );
}
}
}
}
The core:
package com.samii.restful;
import java.util.ArrayList;
import java.util.Set;
import java.lang.Object;
import com.clarkparsia.pellet.owlapi.PelletReasoner;
import com.clarkparsia.pellet.owlapi.PelletReasonerFactory;
import org.mindswap.pellet.exceptions.InconsistentOntologyException;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.AddAxiom;
import org.semanticweb.owlapi.model.RemoveAxiom;
import org.semanticweb.owlapi.model.OWLAxiom;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLDatatype;
import org.semanticweb.owlapi.model.OWLFunctionalDataPropertyAxiom;
import org.semanticweb.owlapi.model.OWLIndividual;
import org.semanticweb.owlapi.model.OWLDataProperty;
import org.semanticweb.owlapi.model.OWLDataFactory;
import org.semanticweb.owlapi.model.OWLLiteral;
import org.semanticweb.owlapi.model.OWLNamedIndividual;
import org.semanticweb.owlapi.model.OWLObjectProperty;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyManager;
import org.semanticweb.owlapi.reasoner.FreshEntitiesException;
import org.semanticweb.owlapi.reasoner.Node;
import org.semanticweb.owlapi.reasoner.NodeSet;
import org.semanticweb.owlapi.reasoner.ReasonerInterruptedException;
import org.semanticweb.owlapi.reasoner.TimeOutException;
import org.semanticweb.owlapi.vocab.OWL2Datatype;
import org.semanticweb.owlapi.util.ShortFormProvider;
import org.semanticweb.owlapi.util.SimpleShortFormProvider;
import org.semanticweb.owlapi.io.SystemOutDocumentTarget;
import org.semanticweb.owlapi.io.OWLFunctionalSyntaxOntologyFormat;
public class OWLManagement {
OWLOntologyManager _manager;
OWLOntology _ontology;
OWLDataFactory _factory;
PelletReasoner _reasoner;
OWLManagement(String ontology_file_path){
_manager = OWLManager.createOWLOntologyManager();
_factory = _manager.getOWLDataFactory();
try{
_ontology = _manager.loadOntology(IRI.create( ontology_file_path ));
}
catch(Exception e){
System.out.println("Exception " + e.toString());
}
//_reasoner = PelletReasonerFactory.getInstance().createReasoner(_ontology);
_reasoner = PelletReasonerFactory.getInstance().createNonBufferingReasoner(_ontology);
_reasoner.prepareReasoner();
}
public boolean updateFunctionalObjectsProperty( String URI, String ssubject, String spredicate, String sobject, String stype ){
OWLLiteral literal;
switch(stype){
case "float":
OWLDatatype xsd_float = _factory.getOWLDatatype( OWL2Datatype.XSD_FLOAT );
literal = _factory.getOWLLiteral(sobject , xsd_float);
break;
default:
literal = _factory.getOWLLiteral("undefined type");
break;
}
OWLNamedIndividual individual = _factory.getOWLNamedIndividual(URI, ssubject);
OWLDataProperty data_property = _factory.getOWLDataProperty(URI, spredicate);
//OWLFunctionalDataPropertyAxiom functional_data_property = _factory.getOWLFunctionalDataPropertyAxiom( data_property );
OWLAxiom axiom = _factory.getOWLDataPropertyAssertionAxiom( data_property, individual, literal);
Set<OWLLiteral> literals = _reasoner.getDataPropertyValues( individual, data_property );
if( !literals.isEmpty() ){
//_manager.removeAxiom( _ontology, axiom );
_manager.applyChange(new RemoveAxiom( _ontology, axiom) );
}
_manager.applyChange(new AddAxiom( _ontology, axiom) );
return true;
}
public void printOntology(){
try{
// print out the ontology on System.out
_manager.saveOntology(_ontology, new OWLFunctionalSyntaxOntologyFormat(), new SystemOutDocumentTarget());
} catch(Exception e){
System.out.println("[OWLManagement].printOntology() -> Catched exception:");
System.out.println("Exception " + e.toString());
}
//_manager.saveOntology(o, new OWLXMLOntologyFormat(), documentIRI2);
// save in RDF/XML
//_manager.saveOntology(o, documentIRI2);
// Remove the ontology from the manager
//_manager.removeOntology(o);
}
public ArrayList<Object> queryDataProperty( String URI, String ssubject, String spredicate ){
OWLNamedIndividual individual = _factory.getOWLNamedIndividual(URI, ssubject);
OWLDataProperty data_property = _factory.getOWLDataProperty(URI, spredicate);
Set<OWLLiteral> literals = null;
try{
literals = _reasoner.getDataPropertyValues( individual, data_property );
System.out.println("[OWLManagement].printOntology() -> Number of literals: " + literals.size() );
} catch( InconsistentOntologyException e ){
System.out.println("[OWLManagement].printOntology() -> Catched InconsistentOntologyException:");
System.out.println("Exception " + e.toString());
} catch( FreshEntitiesException e ){
System.out.println("[OWLManagement].printOntology() -> Catched FreshEntitiesException:");
System.out.println("Exception " + e.toString());
} catch( ReasonerInterruptedException e ){
System.out.println("[OWLManagement].printOntology() -> Catched ReasonerInterruptedException:");
System.out.println("Exception " + e.toString());
} catch( TimeOutException e ){
System.out.println("[OWLManagement].printOntology() -> Catched TimeOutException:");
System.out.println("Exception " + e.toString());
} catch( Exception e){
System.out.println("[OWLManagement].printOntology() -> Catched exception:");
System.out.println("Exception " + e.toString());
}
ArrayList<Object> objects = new ArrayList<Object>();
if( !literals.isEmpty() ){
for(OWLLiteral literal: literals){
if( literal.isInteger() ){
objects.add( literal.parseInteger() );
} else if( literal.isFloat() ){
objects.add( literal.parseFloat() );
} else if( literal.isDouble() ){
objects.add( literal.parseDouble() );
} else if( literal.isBoolean() ){
objects.add( literal.parseBoolean() );
} else{
objects.add( literal.getLiteral() );
}
}
}
System.out.println("[OWLManagement].printOntology() -> Number of objects: " + literals.size() );
return objects;
}
}
and my ontolgy
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE rdf:RDF [
<!ENTITY owl "http://www.w3.org/2002/07/owl#" >
<!ENTITY owl11 "http://www.w3.org/2006/12/owl11#" >
<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" >
<!ENTITY owl11xml "http://www.w3.org/2006/12/owl11-xml#" >
<!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" >
<!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
<!ENTITY CR-owl-guide-20030818 "http://www.w3.org/TR/2003/CR-owl-guide-20030818/" >
<!ENTITY local "file:///C:/Users/cclercq/.eclipse/ws_Samii/Samii/WebContent/Ontologies/justAtest_RDFXML#" >
<!ENTITY swrlb "http://www.w3.org/2003/11/swrlb#" >
<!ENTITY swrl "http://www.w3.org/2003/11/swrl#" >
]>
<rdf:RDF xml:base ="file:///C:/Users/cclercq/.eclipse/ws_Samii/Samii/WebContent/Ontologies/justAtest_RDFXML"
xmlns ="file:///C:/Users/cclercq/.eclipse/ws_Samii/Samii/WebContent/Ontologies/justAtest_RDFXML#"
xmlns:local="file:///C:/Users/cclercq/.eclipse/ws_Samii/Samii/WebContent/Ontologies/justAtest_RDFXML#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:var="urn:swrl#"
xmlns:xml="http://www.w3.org/XML/1998/namespace"
xmlns:swrlb="http://www.w3.org/2003/11/swrlb#"
xmlns:swrl="http://www.w3.org/2003/11/swrl#">
<!--owl:Ontology rdf:about="file:///C:/Users/cclercq/.eclipse/ws_Samii/Samii/WebContent/Ontologies/justAtest_RDFXML#"/-->
<owl:Ontology rdf:about=""/>
<!--Defining classes about robots-->
<owl:Class rdf:about="&local;Robot"/>
<owl:Class rdf:about="&local;Humanoid">
<rdfs:subClassOf rdf:resource="&local;Robot"/>
</owl:Class>
<owl:AllDisjointClasses>
<owl:members rdf:parseType="Collection">
<owl:Class rdf:about="&local;Animal"/>
<owl:Class rdf:about="&local;Robot"/>
</owl:members>
</owl:AllDisjointClasses>
<!--Defining classes about animals-->
<owl:Class rdf:about="&local;Animal"/>
<owl:Class rdf:about="&local;Mammal"/>
<owl:Class rdf:about="&local;Human">
<rdfs:subClassOf rdf:resource="&local;Mammal"/>
</owl:Class>
<owl:Class rdf:about="&local;Person">
<owl:equivalentClass rdf:resource="&local;Human"/>
</owl:Class>
<owl:Class rdf:about="&local;Man">
<rdfs:subClassOf rdf:resource="&local;Human"/>
</owl:Class>
<owl:Class rdf:about="&local;Woman">
<rdfs:subClassOf rdf:resource="&local;Human"/>
</owl:Class>
<owl:AllDisjointClasses>
<owl:members rdf:parseType="Collection">
<owl:Class rdf:about="&local;Man"/>
<owl:Class rdf:about="&local;Woman"/>
</owl:members>
</owl:AllDisjointClasses>
<owl:ObjectProperty rdf:about="&local;hasRobot">
<rdfs:domain rdf:resource="&local;Human"/>
<rdfs:range rdf:resource="&local;Robot"/>
</owl:ObjectProperty>
<owl:DatatypeProperty rdf:about="&local;hasAlert"/>
<!--owl:DatatypeProperty rdf:about="&local;hasAlert">
<rdfs:range rdf:resource="&xsd;string"/>
</owl:DatatypeProperty-->
<!--rdfs:Property rdf:about="&local;hasAlert">
<rdfs:domain rdf:resource="&local;Robot"/>
<rdfs:range rdf:resource="&xsd;string"/>
</rdfs:Property-->
<owl:DatatypeProperty rdf:about="&local;hasTemperature">
<rdf:type rdf:resource="&owl;FunctionalProperty"/>
<!--rdfs:range rdf:resource="&xsd;nonNegativeInteger"/-->
</owl:DatatypeProperty>
<owl:DatatypeProperty rdf:about="&local;hasTension">
<rdf:type rdf:resource="&owl;FunctionalProperty"/>
<!--rdfs:range rdf:resource="&xsd;nonNegativeInteger"/-->
</owl:DatatypeProperty>
<owl:NamedIndividual rdf:about="&local;Charles">
<rdf:type rdf:resource="&local;Man"/>
<!--local:hasTension rdf:datatype="&xsd;float">14</local:hasTension-->
</owl:NamedIndividual>
<owl:NegativePropertyAssertion>
<owl:sourceIndividual rdf:resource="&local;Charles"/>
<owl:assertionProperty rdf:resource="&local;hasRobot"/>
<owl:targetIndividual rdf:resource="&local;Samii"/>
</owl:NegativePropertyAssertion>
<owl:NamedIndividual rdf:about="&local;Walid">
<rdf:type rdf:resource="&local;Man"/>
<local:hasRobot rdf:resource="&local;Samii"/>
<local:hasTemperature rdf:datatype="&xsd;float">37.5</local:hasTemperature>
</owl:NamedIndividual>
<owl:NamedIndividual rdf:about="&local;Samii">
<rdf:type rdf:resource="&local;Humanoid"/>
</owl:NamedIndividual>
<!-- Rules -->
<swrl:Variable rdf:about="&local;x" />
<swrl:Variable rdf:about="&local;alert" />
<swrl:Imp rdf:about="&local;ruleAlertTensionBasse">
<swrl:head rdf:parseType="Collection">
<swrl:DatavaluedPropertyAtom>
<swrl:propertyPredicate rdf:resource="&local;hasAlert"/>
<swrl:argument1 rdf:resource="&local;Samii" />
<swrl:argument2 rdf:datatype="&xsd;string">T'as tension est drôlement basse</swrl:argument2>
</swrl:DatavaluedPropertyAtom>
</swrl:head>
<swrl:body rdf:parseType="Collection">
<swrl:DatavaluedPropertyAtom>
<swrl:propertyPredicate rdf:resource="&local;hasTension"/>
<swrl:argument1 rdf:resource="&local;Charles" />
<swrl:argument2 rdf:resource="&local;x" />
</swrl:DatavaluedPropertyAtom>
<swrl:BuiltinAtom>
<swrl:builtin rdf:resource="&swrlb;lessThan" />
<swrl:arguments>
<rdf:List>
<rdf:first rdf:resource="&local;x"/>
<rdf:rest>
<rdf:List>
<rdf:first rdf:datatype="&xsd;float">14.0</rdf:first>
<rdf:rest rdf:resource="&rdf;nil"/>
</rdf:List>
</rdf:rest>
</rdf:List>
</swrl:arguments>
</swrl:BuiltinAtom>
</swrl:body>
</swrl:Imp>
<swrl:Imp rdf:about="&local;ruleAlertTensionHaute">
<swrl:head rdf:parseType="Collection">
<swrl:DatavaluedPropertyAtom>
<swrl:propertyPredicate rdf:resource="&local;hasAlert"/>
<swrl:argument1 rdf:resource="&local;Samii" />
<swrl:argument2 rdf:datatype="&xsd;string">T'as tension est drôlement haute</swrl:argument2>
</swrl:DatavaluedPropertyAtom>
</swrl:head>
<swrl:body rdf:parseType="Collection">
<swrl:DatavaluedPropertyAtom>
<swrl:propertyPredicate rdf:resource="&local;hasTension"/>
<swrl:argument1 rdf:resource="&local;Charles" />
<swrl:argument2 rdf:resource="&local;x" />
</swrl:DatavaluedPropertyAtom>
<swrl:BuiltinAtom>
<swrl:builtin rdf:resource="&swrlb;greaterThan" />
<swrl:arguments>
<rdf:List>
<rdf:first rdf:resource="&local;x"/>
<rdf:rest>
<rdf:List>
<rdf:first rdf:datatype="&xsd;float">14.0</rdf:first>
<rdf:rest rdf:resource="&rdf;nil"/>
</rdf:List>
</rdf:rest>
</rdf:List>
</swrl:arguments>
</swrl:BuiltinAtom>
</swrl:body>
</swrl:Imp>
</rdf:RDF>
The output of my test case:
== Before adding axiom ==
Prefix(:=<file:///C:/Users/cclercq/.eclipse/ws_Samii/Samii/WebContent/Ontologies/justAtest_RDFXML#>)
Prefix(owl:=<http://www.w3.org/2002/07/owl#>)
Prefix(rdf:=<http://www.w3.org/1999/02/22-rdf-syntax-ns#>)
Prefix(var:=<urn:swrl#>)
Prefix(xml:=<http://www.w3.org/XML/1998/namespace>)
Prefix(xsd:=<http://www.w3.org/2001/XMLSchema#>)
Prefix(rdfs:=<http://www.w3.org/2000/01/rdf-schema#>)
Prefix(swrl:=<http://www.w3.org/2003/11/swrl#>)
Prefix(local:=<file:///C:/Users/cclercq/.eclipse/ws_Samii/Samii/WebContent/Ontologies/justAtest_RDFXML#>)
Prefix(owl11:=<http://www.w3.org/2006/12/owl11#>)
Prefix(swrlb:=<http://www.w3.org/2003/11/swrlb#>)
Prefix(owl11xml:=<http://www.w3.org/2006/12/owl11-xml#>)
Prefix(CR-owl-guide-20030818:=<http://www.w3.org/TR/2003/CR-owl-guide-20030818/>)
Ontology(<file:///C:/Users/cclercq/.eclipse/ws_Samii/Samii/WebContent/Ontologies/justAtest_RDFXML>
Declaration(Class(local:Animal))
Declaration(Class(local:Human))
Declaration(Class(local:Humanoid))
Declaration(Class(local:Mammal))
Declaration(Class(local:Man))
Declaration(Class(local:Person))
Declaration(Class(local:Robot))
Declaration(Class(local:Woman))
Declaration(ObjectProperty(local:hasRobot))
Declaration(DataProperty(local:hasAlert))
Declaration(DataProperty(local:hasTemperature))
Declaration(DataProperty(local:hasTension))
Declaration(NamedIndividual(local:Charles))
Declaration(NamedIndividual(local:Samii))
Declaration(NamedIndividual(local:Walid))
############################
# Object Properties
############################
# Object Property: local:hasRobot (local:hasRobot)
ObjectPropertyDomain(local:hasRobot local:Human)
ObjectPropertyRange(local:hasRobot local:Robot)
############################
# Data Properties
############################
# Data Property: local:hasTemperature (local:hasTemperature)
FunctionalDataProperty(local:hasTemperature)
# Data Property: local:hasTension (local:hasTension)
FunctionalDataProperty(local:hasTension)
############################
# Classes
############################
# Class: local:Animal (local:Animal)
DisjointClasses(local:Animal local:Robot)
# Class: local:Human (local:Human)
EquivalentClasses(local:Human local:Person)
SubClassOf(local:Human local:Mammal)
# Class: local:Humanoid (local:Humanoid)
SubClassOf(local:Humanoid local:Robot)
# Class: local:Man (local:Man)
SubClassOf(local:Man local:Human)
DisjointClasses(local:Man local:Woman)
# Class: local:Woman (local:Woman)
SubClassOf(local:Woman local:Human)
############################
# Named Individuals
############################
# Individual: local:Charles (local:Charles)
ClassAssertion(local:Man local:Charles)
NegativeObjectPropertyAssertion(local:hasRobot local:Charles local:Samii)
# Individual: local:Samii (local:Samii)
ClassAssertion(local:Humanoid local:Samii)
# Individual: local:Walid (local:Walid)
ClassAssertion(local:Man local:Walid)
ObjectPropertyAssertion(local:hasRobot local:Walid local:Samii)
DataPropertyAssertion(local:hasTemperature local:Walid "37.5"^^xsd:float)
DLSafeRule(Body(DataPropertyAtom(local:hasTension local:Charles Variable(local:x)) BuiltInAtom(swrlb:greaterThan Variable(local:x) "14.0"^^xsd:float))Head(DataPropertyAtom(local:hasAlert local:Samii "T'as tension est drôlement haute"^^xsd:string)))
DLSafeRule(Body(DataPropertyAtom(local:hasTension local:Charles Variable(local:x)) BuiltInAtom(swrlb:lessThan Variable(local:x) "14.0"^^xsd:float))Head(DataPropertyAtom(local:hasAlert local:Samii "T'as tension est drôlement basse"^^xsd:string)))
)[main].main =>
== Query ==
[OWLManagement].printOntology() -> Number of literals: 0
[OWLManagement].printOntology() -> Number of objects: 0
[main].main() -> Number of literals: 0
[main].main =>
== After adding axiom ==
Prefix(:=<file:///C:/Users/cclercq/.eclipse/ws_Samii/Samii/WebContent/Ontologies/justAtest_RDFXML#>)
Prefix(owl:=<http://www.w3.org/2002/07/owl#>)
Prefix(rdf:=<http://www.w3.org/1999/02/22-rdf-syntax-ns#>)
Prefix(var:=<urn:swrl#>)
Prefix(xml:=<http://www.w3.org/XML/1998/namespace>)
Prefix(xsd:=<http://www.w3.org/2001/XMLSchema#>)
Prefix(rdfs:=<http://www.w3.org/2000/01/rdf-schema#>)
Prefix(swrl:=<http://www.w3.org/2003/11/swrl#>)
Prefix(local:=<file:///C:/Users/cclercq/.eclipse/ws_Samii/Samii/WebContent/Ontologies/justAtest_RDFXML#>)
Prefix(owl11:=<http://www.w3.org/2006/12/owl11#>)
Prefix(swrlb:=<http://www.w3.org/2003/11/swrlb#>)
Prefix(owl11xml:=<http://www.w3.org/2006/12/owl11-xml#>)
Prefix(CR-owl-guide-20030818:=<http://www.w3.org/TR/2003/CR-owl-guide-20030818/>)
Ontology(<file:///C:/Users/cclercq/.eclipse/ws_Samii/Samii/WebContent/Ontologies/justAtest_RDFXML>
Declaration(Class(local:Animal))
Declaration(Class(local:Human))
Declaration(Class(local:Humanoid))
Declaration(Class(local:Mammal))
Declaration(Class(local:Man))
Declaration(Class(local:Person))
Declaration(Class(local:Robot))
Declaration(Class(local:Woman))
Declaration(ObjectProperty(local:hasRobot))
Declaration(DataProperty(local:hasAlert))
Declaration(DataProperty(local:hasTemperature))
Declaration(DataProperty(local:hasTension))
Declaration(NamedIndividual(local:Charles))
Declaration(NamedIndividual(local:Samii))
Declaration(NamedIndividual(local:Walid))
############################
# Object Properties
############################
# Object Property: local:hasRobot (local:hasRobot)
ObjectPropertyDomain(local:hasRobot local:Human)
ObjectPropertyRange(local:hasRobot local:Robot)
############################
# Data Properties
############################
# Data Property: local:hasTemperature (local:hasTemperature)
FunctionalDataProperty(local:hasTemperature)
# Data Property: local:hasTension (local:hasTension)
FunctionalDataProperty(local:hasTension)
############################
# Classes
############################
# Class: local:Animal (local:Animal)
DisjointClasses(local:Animal local:Robot)
# Class: local:Human (local:Human)
EquivalentClasses(local:Human local:Person)
SubClassOf(local:Human local:Mammal)
# Class: local:Humanoid (local:Humanoid)
SubClassOf(local:Humanoid local:Robot)
# Class: local:Man (local:Man)
SubClassOf(local:Man local:Human)
DisjointClasses(local:Man local:Woman)
# Class: local:Woman (local:Woman)
SubClassOf(local:Woman local:Human)
############################
# Named Individuals
############################
# Individual: local:Charles (local:Charles)
ClassAssertion(local:Man local:Charles)
NegativeObjectPropertyAssertion(local:hasRobot local:Charles local:Samii)
DataPropertyAssertion(local:hasTension local:Charles "10.0"^^xsd:float)
# Individual: local:Samii (local:Samii)
ClassAssertion(local:Humanoid local:Samii)
# Individual: local:Walid (local:Walid)
ClassAssertion(local:Man local:Walid)
ObjectPropertyAssertion(local:hasRobot local:Walid local:Samii)
DataPropertyAssertion(local:hasTemperature local:Walid "37.5"^^xsd:float)
DLSafeRule(Body(DataPropertyAtom(local:hasTension local:Charles Variable(local:x)) BuiltInAtom(swrlb:greaterThan Variable(local:x) "14.0"^^xsd:float))Head(DataPropertyAtom(local:hasAlert local:Samii "T'as tension est drôlement haute"^^xsd:string)))
DLSafeRule(Body(DataPropertyAtom(local:hasTension local:Charles Variable(local:x)) BuiltInAtom(swrlb:lessThan Variable(local:x) "14.0"^^xsd:float))Head(DataPropertyAtom(local:hasAlert local:Samii "T'as tension est drôlement basse"^^xsd:string)))
)[main].main =>
== Query ==
[OWLManagement].printOntology() -> Number of literals: 2
[OWLManagement].printOntology() -> Number of objects: 2
[main].main() -> Number of literals: 2
->Samii hasAlert T'as tension est drôlement haute
->Samii hasAlert T'as tension est drôlement basse
It seems that the problem comes from the version of Pellet or OWL-API used. I was originally using openllet 2.5.1.
Using the last "official" version of Pellet (2.3.6-ansell) with its version of OWL-API (3.4.9.2-ansell), the result is what I was expecting:
with "tension" < 14:
== Query ==
[OWLManagement].printOntology() -> Number of literals: 1
[OWLManagement].printOntology() -> Number of objects: 1
[main].main() -> Number of literals: 1
->Samii hasAlert T'as tension est drôlement basse
with "tension" >14
== Query ==
[OWLManagement].printOntology() -> Number of literals: 1
[OWLManagement].printOntology() -> Number of objects: 1
[main].main() -> Number of literals: 1
->Samii hasAlert T'as tension est drôlement haute
By the way, I tried with the version of ignazio1977 to used OWL-API version 4.0.2, but I got the same problem than with openllet 2.5.1.

CakePHP 3.x - Getting database fields depending on Locale settings

I got to develop a multi language website. It has more that 4 languages at the same time used in database. It's always following scheme:
field_%lang%
ex. id | title_en | title_de | description_en | description_de
As its quite simple I was thinking to write a function I could use in both controllers and views (global Entity?) in order to keep my code DRY.
//function
public function __($field, $language = null){
if( $language === null ){
list( $language ) = split('_', I18n::Locale());
}
$newField = $field . '_' . strtolower( $language );
if( $this->has( $newField ) ){
return $this->{ $newField };
}else{
throw new NotFoundException('Could not find "' . $newField . '" field');
}
}
//usage
$result->__('title'); //returns title_en depending on Locale
$result->__('title', 'de'); //always returns title_de
The thing is that I have no idea where to implement it without braking conventions. I was thinking about Entities but as I understand there is no "global" Entity that works for all models?
All ideas and suggestions are welcome!
Mike
\Cake\ORM\Entity is the base class of all your entities, you are not going to modify a built-in CakePHP class but nothing prevent you from creating your own superclass.
Let's call it AppEntity, just create a AppEntity.php file under src/Model/Entity and put your code inside:
<?php
namespace App\Model\Entity;
use Cake\I18n\I18n;
use Cake\Network\Exception\NotFoundException;
class AppEntity extends \Cake\ORM\Entity {
public function __($field, $language = null){
if( $language === null ){
list( $language ) = split('_', I18n::Locale());
}
$newField = $field . '_' . strtolower( $language );
if( $this->has( $newField ) ){
return $this->{ $newField };
}else{
throw new NotFoundException('Could not find "' . $newField . '" field');
}
}
}
Then, when you create an entity class, instead of extending \Cake\ORM\Entity you extend AppEntity:
<?php
namespace App\Model\Entity;
class User extends AppEntity {
} ;
?>

ActiveDirectoryMembershipProvider - Can't use secure connection protection

I try to use ASP.Net's MembershipProvider to give access only to certain users. This is backed up by an ADAM instance.
I use some test-code which runs just fine:
public static DataTable getADValuesByParameter(string strFilter, string strLDAPUser, string strLDAPPath, string strLDAPPWD, string strLDAPProperties)
{
DataTable functionReturnValue = default(DataTable);
string[] arrLDAP = null;
DirectoryEntry rootEntry = new DirectoryEntry();
DirectorySearcher searcher = new DirectorySearcher();
SearchResultCollection results = default(SearchResultCollection);
DataTable dtExchangeUserData = new DataTable();
arrLDAP = strLDAPProperties.Split(new char[] { ',' });
rootEntry.Path = strLDAPPath;
rootEntry.Username = strLDAPUser;
rootEntry.Password = strLDAPPWD;
rootEntry.AuthenticationType = AuthenticationTypes.Secure;
searcher.SearchRoot = rootEntry;
searcher.SearchScope = SearchScope.Subtree;
searcher.Filter = strFilter;
searcher.PropertiesToLoad.AddRange(arrLDAP);
//var value = rootEntry.NativeObject;
results = searcher.FindAll();
Int16 si = default(Int16);
foreach (SearchResult result in results)
{
si = 0;
object[] arrKeyValue = new object[result.Properties.Count - 1];
// -2 weil property "adspath" nicht dazu gehört, und .count -1 weil 0 basierendes array
if ((result != null))
{
System.Collections.IEnumerator myEnumerator = arrLDAP.GetEnumerator();
while (myEnumerator.MoveNext())
{
foreach (string Key in result.Properties.PropertyNames)
{
if (Key != "adspath")
{
if (Key.Equals(((string)myEnumerator.Current).ToLower()))
{
if (dtExchangeUserData.Columns[Key] == null)
dtExchangeUserData.Columns.Add(Key);
if (Key.Equals("objectguid"))
{
arrKeyValue[si] = new Guid(((byte[])result.Properties[Key][0]));
}
else
{
arrKeyValue[si] = result.Properties[Key][0].ToString();
}
si++;
}
}
}
}
if (arrKeyValue.Length > 0)
dtExchangeUserData.Rows.Add(arrKeyValue);
}
}
functionReturnValue = dtExchangeUserData;
dtExchangeUserData.Dispose();
rootEntry.Close();
rootEntry.Dispose();
return functionReturnValue;
}
Here, I query the ADAM manually. Although the code is badly written, it works. Note how I use "AuthenticationTypes.Secure".
Now, when I try to do the same thing (same connectionPath, username, password and so on) with the ActiveDirectoryMembershipProvider, it gives me (roughly translated from German):
ConfigurationErrorsException: Can't
establish a secure connection over
SSL.
This happens when I call
Membership.ValidateUser()
Here are the relevant parts from the Web.config file:
<connectionStrings>
<add name="ADConnectionString" connectionString="LDAP://server.com/OU=users,DC=test,DC=adam"/>
</connectionStrings>
<authentication mode="Forms" >
<forms loginUrl="~/Login.aspx/Test/" timeout="2880" />
</authentication>
<authorization>
<deny users ="?" />
</authorization>
<!--<identity impersonate="true" />-->
<trust level="Full" />
<membership defaultProvider="MyMembershipProvider">
<providers>
<add name="MyMembershipProvider"
type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0,Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="ADConnectionString"
connectionUsername="[domain]\[user]"
connectionPassword="[password]"
connectionProtection="Secure"
enableSearchMethods="true"
/>
</providers>
</membership>
It doesn't matter whether I use impersonation or not (to be honest, I don't really know what it does anyway). Trust-level doesn't change anything either.
When I use connectionProtection="None" instead, it gives me (again translated) "Wrong username or password". I get the same error when I use "AuthenticationTypes.None" in the manual example.
What am I doing wrong?
Thanks for your time...

Resources