In the OWL API, I am unable to find a way to retrieve the equivalent class for a datatype that defines an enumeration of valid values. When I have an OWLDatatype in hand, how do I get a set of allowed values?
[I tried pasting RDF/XML as a code block here, but it doesn't work. I even looked at the markdown help. Please tell me how to do that.]
The ontology is using the following construct:
rdfs:Datatype
owl:equivalentClass
rdfs:Datatype
owl:oneOf
rdf:Description
rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#List"
If understand correctly, you have a specific class "c" that has been defined as equivalent to oneOf many individuals, then I think this is one way to get those "allowed values":
Set<OWLClassAxiom> allAx=localOntology.getAxioms(c);
for(OWLClassAxiom ax: allAx){
if(ax.getAxiomType()==AxiomType.EQUIVALENT_CLASSES)
for(OWLClassExpression nce :ax.getNestedClassExpressions())
if(nce.getClassExpressionType()==ClassExpressionType.OBJECT_ONE_OF)
for(OWLNamedIndividual temp: nce.getIndividualsInSignature())
System.out.println(temp);
}
Here's what I came up with:
for (OWLDatatype dt : o.getDatatypesInSignature(Imports.INCLUDED)) {
logger.info("found datatype {} labeled '{}'", dt, getOWLEntityLabel(dt));
Set<OWLDatatypeDefinitionAxiom> datatypeDefinitions = o.getDatatypeDefinitions(dt);
for (OWLDatatypeDefinitionAxiom definitionAxiom : datatypeDefinitions) {
logger.info("found datatype definition '{}'", definitionAxiom);
OWLDataRange dataRange = definitionAxiom.getDataRange();
if ( ! dataRange.isDatatype()) {
logger.info("looks like an enumeration");
OWLDataOneOf owlDataOneOf = (OWLDataOneOf) dataRange;
Set<OWLLiteral> values = owlDataOneOf.getValues();
for (OWLLiteral value : values) {
logger.info("Found literal value '{}'", value.getLiteral());
}
}
}
}
I really don't like the cast to OWLDataOneOf. There must be a better way.
Related
I want to check if a value exists in an array of objects.
My array looks something like this:
[
0: {
id: 'unique_obj_id',
item: {
id: 'unique_item_id',
...
},
...
},
1: {...}
]
The objects in the array can be one of many interface types (depending on my api call, here: resource strings represent these interfaces, which are defined somewhere else). But one array will always consist of the same interface types for a given data request.
I'm trying to write a reusable function to check whether given_id exists for any object in the array for obj.item.id.
So far I've managed to write the correct logic but typescript throws some exceptions that I can't seem to figure out. shopApprovalData is a collection of interfaces each following the above object structure accessible by the indices of resource.
export type ApprovalResource = 'str1' | 'str2' | 'str3' | 'str4' | 'str5';
export const checkApprovalItem = (given_id: string, resource: ApprovalResource) => {
const shopApprovalData = useShopApprovals();
if (shopApprovalData && shopApprovalData[resource]) {
const resourceApprovalData = shopApprovalData[resource];
if (resourceApprovalData.find(e => e.item.id === id)) {
return true;
}
}
return false;
}
Typescript shows me that shopApprovalData and itemApprovalData is possibly undefined and that the expression find() is not callable since signatures of members of the union type are not compatible with each other. (Apparently, some removes the error, why?)
What approach should I choose instead to check whether the given_id exists in any object of the array?
Based on your usecase, i create this code sandbox: https://codesandbox.io/s/stackoverflow-answer-ke9drk?file=/src/index.ts
explanation:
Type wont compile, so we need something to mark what the interface of the object.
Also i may confused by your code shopApprovalData[resource] what do you want to achieve here? for example, if resource is str1 shopApprovalData[resource] will always return undefined because no index str1 in Array
I hope it help,
Best Regards
I have an API that receive a JSON document with classes, properties and axioms of an ontology. The file looks like this:
{
"id": "myontologyid",
"outformat": "OWL",
"ontoclass": ["Person", "Man", "Woman", "Animal", "Rational", "Arm"],
"ontoaxioms": ["Man subClassOf (Person)", "Person EquivalentTo: (Man OR Woman)", "hasBrother max 2 xsd:integer"],
"ontoproperties": ["hasPart", "isBrotherOf", "hasBrother"]
}
The ontoaxioms key is an array with all the axioms of the ontology. The values of this array MUST be in Manchester syntax as I will use the ManchesterOWLSyntaxParser to parse.
When I try to parse this code, I get the following error on hasBrother max 2 xsd:integer axiom:
[apache-tomcat-8.5.69-2]: org.semanticweb.owlapi.manchestersyntax.renderer.ParserException: Encountered |EOF| at line 1 column 29. Expected one of:
SubClassOf:
or
and
DisjointWith:
EquivalentTo:
I believe the Manchester syntax is incorrect. But I couldn't find any reference or documentation of OWL-API which indicates how to use it. Is there some?
Below is part of my code which tries to parse the axioms:
ManchesterOWLSyntaxParserImpl parser = (ManchesterOWLSyntaxParserImpl) OWLManager.createManchesterParser();
parser.setOWLEntityChecker(entityChecker);
try {
for (int i = 0; i < this.axiomas.length(); i++) {
parser.setStringToParse(this.axiomas.getString(i));
owlOntology.addAxiom(parser.parseAxiom());
}
} catch (Exception e) {
System.out.print(e.toString());
return null;
}
The questions are:
How to solve this EOF error?
How to insert correctly Manchester Syntax into OWL-API?
Where can I find some documentation on how to use Manchester Syntax to parse ontologies?
Many thanks in advance.
Your use of OWLAPI classes appears correct. The problem with the input that something else is expected to follow, i.e., that's not a full axiom.
Is the intent to say that hasBrother can only appear twice for an individual and has integer range?
As it happens, there's a unit test in the OWLAPI contract module that uses this string as input for parsing:
String in = "p max 1 owl:real";
ManchesterOWLSyntaxParser parser = OWLManager.createManchesterParser();
parser.setStringToParse(in);
OWLClassExpression cl = parser.parseClassExpression();
The string has the same format as what you're trying to parse, and it gives a class expression, not an axiom - specifically, a qualified max cardinality restriction for a data property. This can be the superclass or the subclass in a subclass axiom, for example, but the rest of the axiom is not present.
In Azure Data Factory v2 (ADFv2) I am having trouble passing a parameter whose value is an expression that needs evaluated at runtime.
For example, I have a set of extracts I want to download daily from the same LinkedService/Connection. I want a pipeline with a Foreach to be able to input a JSON pipeline parameter with a list of configuration for each report type (this I can do). "but" when I have one of those configuration KVPairs with value that is an expression, the expression does not seem to be evaluated.
here is an example of a Foreach parameter set that works for an SFTP LinkedService :
[ { "dirPath" : "/dirPath" ,"fileFilter" : "this_works_fine_20180307*.txt" } ]
here is an example of a Foreach parameter set that does not match the files I need to get.
(assume utcnow('yyyyMMdd') returns 20180307
[ { "dirPath" : "/dirPath" ,"fileFilter" : "this_does_NOT_work_#{utcnow('yyyyMMdd')}*.txt" } ]
This assumes that in the underlying Copy activity I am passing the dataset parameter fileFilter as
#item().fileFilter
...and in the dataset, the value of the fileFilter is an expression with value
#dataset().fileFilter
...I have also tried to wrap the argument completely as:
[ { "dirPath" : "/dirPath" ,"fileFilter" : "#toLower(concat(string('this_does_NOT_work_'),string(utcnow('yyyyMMdd')),string('*.txt') )))" } ]
...If you have suggestions/guidance, please let me know.
Thanks,
J
Try to put the fileFilter parameter directly in pipeline parameter.
Something like this will work:
[ { "dirPath" : "/dirPath" ,"fileFilter" : "this_works_fine_#{formatDateTime(utcnow(), 'yyyy')}#{formatDateTime(utcnow(), 'MM')}#{formatDateTime(utcnow(), 'dd')}*.txt" } ]
Is there any straight-forward way in OWLAPI to find all IRIs used in an ontology which have not been identified as Entities i.e. have not been declared and are not used in a context which would allowed them to be identified as a specific entity type? Hoping for something analogous to OWLOntology.signature(), didn't see anything.
An example of that situation appears in BFO 2.0 (http://purl.obolibrary.org/obo/bfo.owl) :
<rdf:Description rdf:about="http://example.com/bfo-spec-label">
<obo:IAO_0000119>Person:Alan Ruttenberg</obo:IAO_0000119>
</rdf:Description>
Here http://example.com/bfo-spec-label is just a "bare" IRI of unknown entity type and thus does not appear in the ontology signature.
Couldn't find any elegant way to find all of these bare IRI's but these can be found by looking in all places they could possibly occur. A simple method would look like:
private List findBareIRIs(OWLOntology onto) {
List bares = new ArrayList();
// bare IRIs can occur as AnnotationSubjects, AnnotationObjects or the domain/range of AnnotationProperties
List<OWLAnnotationAssertionAxiom> asserts = OWLAPIStreamUtils.asList(onto.axioms(AxiomType.ANNOTATION_ASSERTION));
List<OWLAnnotationPropertyDomainAxiom> domains = OWLAPIStreamUtils.asList(onto.axioms(AxiomType.ANNOTATION_PROPERTY_DOMAIN));
List<OWLAnnotationPropertyRangeAxiom> ranges = OWLAPIStreamUtils.asList(onto.axioms(AxiomType.ANNOTATION_PROPERTY_RANGE));
//check the subject and values of each AnnotationAsertion
for (OWLAnnotationAssertionAxiom ax : asserts) {
OWLAnnotationSubject subj = ax.getSubject();
OWLAnnotationValue value = ax.getValue();
if (subj.isIRI()) {
bares.add((IRI) subj);
}
if (value.isIRI()) {
bares.add((IRI) value);
}
}
// check the domain and ranges of each AnnotationProperty
for (OWLAnnotationPropertyDomainAxiom ax : domains) {
bares.add(ax.getDomain());
}
for (OWLAnnotationPropertyRangeAxiom ax : ranges) {
bares.add(ax.getRange());
}
return bares;
}
I know there are more elaborate ways to achieve this in Java, but Groovy should have a concise way to do the same as per http://groovy.codehaus.org/Looping
Class Currency.groovy
class Currency {
String name
double rate
}
CurrencyController
def select(){
List<Currency> selectedCurrencies = Currency.getAll(params.currencies)
selectedCurrencies.eachWithIndex { obj, i -> obj.rate = update(obj.name)};
[selectedCurrencies:selectedCurrencies]
}
def update(String sym){
return sym
}
The above code throws:
No signature of method: currencychecker.CurrencyController$_$tt__select_closure12.doCall() is applicable for argument types: (currencychecker.Currency)
Thanks to #dmahapatro, the issue was that I was using an iterator variable obj[i], even though obj itself is the iterated object. The rest is correct!
I experimented with selectCurrencies.each as well instead of selectCurrencies.eachWithIndex however the right one in this case is eachWithIndex