Getting range of data property using OWL API - owl-api

I am using OWL API to get the range of a data property as follows:
OWLDataProperty dataProperty = ontologyManager.getOWLDataFactory().getOWLDataProperty("http://schema.mobivoc.org/powerInKW");
Set<OWLDataPropertyRangeAxiom> ranges = ontology.getOWLOntology().getDataPropertyRangeAxioms(dataProperty);
for (OWLDataPropertyRangeAxiom range : ranges) {
String rangeString = range.getRange().getDataRangeType().getIRI().getIRIString();
}
The property "http://schema.mobivoc.org/powerInKW" has the range xsd:Double. But the above code is returning owl:DataType. While I agree that xsd:Double is an instance of owl:DataType, how to get the actual range, in this case owl:DataType ?

You have getDataRangeType() in your code, which moves you from the range to its type. But what you want is the range, so skip that method and just use the range. You can create a visitor to navigate the different ranges, or you can cast to OWLDatatype for plain datatypes.

Related

kotlin "contains" doesn't work as expected

I am working with a method which filters the preferences which match with the ids, I am using the contains method, but even though the values are the same, the contains is showing a false in each iteration. The method looks like:
private fun filterPreferencesByIds(context: MyPodCastPresenterContext): List<FanPreferences> {
return context.preferences?.filter {
context.ids.contains(it.id)
}
}
The values of the arrays are:
for the context.ids:
"B52594F5-80A4-4B18-B5E2-8F7B12E92958" and "3998EDE7-F84B-4F02-8E15-65F535080100"
And for the context.preferences:
But even though, when the first and the final ids have the same id value as the context.ids, the contains is false in the debug. I think it could be related with the types in the context.ids rows Json$JsonTextNode. Because when I did the same with numeric values hardcoded the compare is successful.
Any ideas?
Thanks!
If the type of FanPreferences.id is String and the type of context.ids list element is JsonTextNode, you won't find an element equal to the given id string, because it's not of String type.
Try mapping your context ids to the list of strings before filtering:
val ids = context.ids.map { it.toString() }.toSet()
return context.preferences?.filter {
ids.contains(it.id)
}
Note that calling toString() on JsonTextNode might be not the best way to get the string data from it. It's better to consult the API documentation of that class to find it out.

Getting rates from an array - json

I am trying to get the rates from this website.
So I connect with website = Faraday.get('https://bitpay.com/api/rates')).status == 200 and then try to parse this.
A segment of the response I get is:
#<Faraday::Response:0x007fcf1ce25688
#env=
#<struct Faraday::Env
method=:get,
body=
"[{\"code\":\"BTC\",\"name\":\"Bitcoin\",\"rate\":1}, {\"code\":\"USD\",\"name\":\"US Dollar\",\"rate\":586.66},{\"code\":\"EUR\",\"name\":\"Eurozone Euro\",\"rate\":528.991322},{\"code\":\"GBP\",\"name\":\"Pound Sterling\",\"rate\":449.441986},{\"code\":\"JPY\",\"name\":\"Japanese Yen\",\"rate\":59907.95922},{\"code\":\"CAD\",\"name\"
When I do a website.body I get a String class of all these values found on that website. I want to parse them though (JSON?) so that I can get each rate as a float.
I tried something JSON.parse(website.body)["GBP"]["rate"].to_f but yet again it cannot work in a string.
The return I get is TypeError: no implicit conversion of String into Integer
I was having a similar (but not the same) format from a different rates website and this is how I was handling it. Do I need to change its format first or is there a different way around it?
You're trying to access to the parsed JSON with the key "GBP" but you have an array. It's like if you did
a = [1,2,3,4,5]
a['foo']
Try out
currencies = JSON.parse(website.body)
currencies.each { |currency| puts currency['rate'] }
and change it like you need

Creating pie chart with array

I am trying to create a Pie chart based on an array (rather than a range). The array is [11,10,1] (I have other code that populates the array).
Dim type_chart As Chart
Dim type_array(2) As Integer
Set type_chart = Charts.Add
type_chart.ChartType = xlPie
type_chart.SeriesCollection(1).Values = type_array
On the last line of the code above, I receive an 'Invalid Parameter' error.
Also, it doesn't have to use an array, but it cannot use a Range.
Your chart needs to work from a range. Find a blank area you can use. Try something like the following:
my_temp_range = "A10:C10"
ActiveSheet.Range(my_temp_range) = type_array
type_chart.SeriesCollection(1).Values = ActiveSheet.Range(my_temp_range)
Once you're working with a temporary range you may not even need the last line (so long as the size of the array doesn't change). You could just set up the chart in advance instead.

Logical-Indexing for Matlab-object-arrays

Is there any way in Matlab R2011b to apply logical-indexing to object-arrays? The objects which fulfill specific condition(s) regarding their properties should be returned. At best the solution is also possible with object-arrays that are a property of another object (aggregation).
In my project there are a lot of entities which have to be identified by their manifold features. Matlab objects with their properties provide a clear data foundation for this purpose. The alternative of using structs (or cells) and arrays of indices seems to be too confusing. Unfortunately the access to the properties of objects is a little bit complicated.
For Example, all Objects in myArray with Element.val==3 should be returned:
elementsValIsThree = myElements(Element.val==3);
Best solution so far:
find([myElements.val]==3);
But this doesn't return the objects and not the absolute index if a subset of myElements is input.
Another attempt returns only the first Element and needs constant properties:
myElements(Element.val==3);
A minimal example with class definition etc. for clarification:
% element.m
classdef Element
properties
val
end
methods
function obj = Element(value)
if nargin > 0 % to allow empty construction
obj.val = value;
end
end
end
end
Create array of Element-Objects:
myElements(4) = Element(3)
Now myElements(4) has val=3.
I'm not sure I understood the question, but the logical index can be generated as
arrayfun(#(e) isequal(e.val,3), myElements);
So, to pick the elements of myElements whose val field equals 3:
elementsValIsThree = myElements(arrayfun(#(e) isequal(e.val,3), myElements));

Converting an object into array/matrix?

I have an object in Matlab created from a third party toolbox. Within the object is a 3x65 double array. If I type the name of the object in the Matlab console, it lists all the contents, and specifically says this 3x65 array is a double. All I want to do is to extract this array into a separate Matlab array. But when I do something like:
x = object.ArrayIWant
I get the error "Access to an object's fields is only permitted within its methods." If I try the following:
x = get(object,'ArrayIWant)
I get the error "Conversion to double from 'toolboxfunction' is not possible. How do get access to this array?!
Look for "Get" methods in the class:
methods(object)
or
methods className
Say it says there is a method called GetArrayIWant, then you'd do:
x = object.GetArrayIWant();

Resources