How do you query OWL Annotations - search

I am searching for the method/tool/syntax to query annotations in an RDF/OWL ontology.
The query engines I have found search classes, properties, individuals, but I have not found one that will search based on the value for example DC:Description

With SPARQL, you should be able to query annotations via the properties you're interested in, for example:
PREFIX dc: <http://purl.org/dc/elements/1.1/>
SELECT ?x ?desc {
?x dc:description ?desc .
}
This method could also be used to retrieve all instances with a particular annotation value, such as:
PREFIX dc: <http://purl.org/dc/elements/1.1/>
SELECT ?x {
?x dc:description "some description string" .
}
Or, you could even try to match based on some REGEX:
PREFIX dc: <http://purl.org/dc/elements/1.1/>
SELECT ?x {
?x dc:description ?desc .
FILTER REGEX(STR(?desc), "^Some regex") .
}

If you are after a programmtic tool and the ontology is OWL you can use the Manchester OWL API:
OWLClass classA = factory.getOWLClass(IRI.create("http://your/url/here#ClassA"));
OWLAnnotationProperty dcProperty = factory.getOWLAnnotationProperty(IRI.create("http://purl.org/dc/elements/1.1/description"));
for (OWLAnnotation annotation : classA.getAnnotations(ontology, dcProperty)) {
OWLLiteral literal = (OWLLiteral) annotation.getValue();
String literalString = literal.getLiteral()
}
That will get you the value of that particular property. "factory" here is an instance of OWLDataFactory.
Hope that helps a little!

Related

Use JOOQ Multiset with custom RecordMapper - How to create Field<List<String>>?

Suppose I have two tables USER_GROUP and USER_GROUP_DATASOURCE. I have a classic relation where one userGroup can have multiple dataSources and one DataSource simply is a String.
Due to some reasons, I have a custom RecordMapper creating a Java UserGroup POJO. (Mainly compatibility with the other code in the codebase, always being explicit on whats happening). This mapper sometimes creates simply POJOs containing data only from the USER_GROUP table, sometimes also the left joined dataSources.
Currently, I am trying to write the Multiset query along with the custom record mapper. My query thus far looks like this:
List<UserGroup> = ctx
.select(
asterisk(),
multiset(select(USER_GROUP_DATASOURCE.DATASOURCE_ID)
.from(USER_GROUP_DATASOURCE)
.where(USER_GROUP.ID.eq(USER_GROUP_DATASOURCE.USER_GROUP_ID))
).as("datasources").convertFrom(r -> r.map(Record1::value1))
)
.from(USER_GROUP)
.where(condition)
.fetch(new UserGroupMapper()))
Now my question is: How to create the UserGroupMapper? I am stuck right here:
public class UserGroupMapper implements RecordMapper<Record, UserGroup> {
#Override
public UserGroup map(Record rec) {
UserGroup grp = new UserGroup(rec.getValue(USER_GROUP.ID),
rec.getValue(USER_GROUP.NAME),
rec.getValue(USER_GROUP.DESCRIPTION)
javaParseTags(USER_GROUP.TAGS)
);
// Convention: if we have an additional field "datasources", we assume it to be a list of dataSources to be filled in
if (rec.indexOf("datasources") >= 0) {
// How to make `rec.getValue` return my List<String>????
List<String> dataSources = ?????
grp.dataSources.addAll(dataSources);
}
}
My guess is to have something like List<String> dataSources = rec.getValue(..) where I pass in a Field<List<String>> but I have no clue how I could create such Field<List<String>> with something like DSL.field().
How to get a type safe reference to your field from your RecordMapper
There are mostly two ways to do this:
Keep a reference to your multiset() field definition somewhere, and reuse that. Keep in mind that every jOOQ query is a dynamic SQL query, so you can use this feature of jOOQ to assign arbitrary query fragments to local variables (or return them from methods), in order to improve code reuse
You can just raw type cast the value, and not care about type safety. It's always an option, evne if not the cleanest one.
How to improve your query
Unless you're re-using that RecordMapper several times for different types of queries, why not do use Java's type inference instead? The main reason why you're not getting type information in your output is because of your asterisk() usage. But what if you did this instead:
List<UserGroup> = ctx
.select(
USER_GROUP, // Instead of asterisk()
multiset(
select(USER_GROUP_DATASOURCE.DATASOURCE_ID)
.from(USER_GROUP_DATASOURCE)
.where(USER_GROUP.ID.eq(USER_GROUP_DATASOURCE.USER_GROUP_ID))
).as("datasources").convertFrom(r -> r.map(Record1::value1))
)
.from(USER_GROUP)
.where(condition)
.fetch(r -> {
UserGroupRecord ug = r.value1();
List<String> list = r.value2(); // Type information available now
// ...
})
There are other ways than the above, which is using jOOQ 3.17+'s support for Table as SelectField. E.g. in jOOQ 3.16+, you can use row(USER_GROUP.fields()).
The important part is that you avoid the asterisk() expression, which removes type safety. You could even convert the USER_GROUP to your UserGroup type using USER_GROUP.convertFrom(r -> ...) when you project it:
List<UserGroup> = ctx
.select(
USER_GROUP.convertFrom(r -> ...),
// ...

Is it possible to change keyword for cross referencing between grammar rules/objects in Xtext?

When I want to make cross referencing between grammar rules in Xtext work, I need to use keyword name for that. E.g.:
Constant:
name=NAME_TERMINAL "=" number=Number;
ConstUsage:
constant=[Constant | NAME_TERMINAL];
Is it possible to change this word to another one (e.g. id) ? I need it e.g. in case when I have rule, which uses parameter name for something else.
you can use a custom implementation of IQualifiedNameProvider e.g. by subclassing DefaultDeclarativeQualifiedNameProvider.
public class MyDslQNP extends DefaultDeclarativeQualifiedNameProvider{
QualifiedName qualifiedName(Element e) {
Package p = (Package) e.eContainer();
return QualifiedName.create(p.getName(), e.getId());
}
}
see https://dietrich-it.de/xtext/2011/07/16/iqualifiednameproviders-in-xtext-2-0.html for the complete example

Download live DBPedia on “is [property] of”?

I want to download all the properties of an entity in the http://pl.dbpedia.org/page/, but when I choose the RDF (N-triple) to download the raw data about an entity, I found that the "is [property] of" properties missing, so how can I get all the properties including the "is [property] of"? Thanks!
For Example, I want to get the raw data(N-triple) of http://pl.dbpedia.org/page/Robin_Wright. How can I get the "is starring of" property?
"is [property] of" is a presentation of inverse relationships.
{ <http://pl.dbpedia.org/resource/Robin_Wright> is ?property of ?subject }
-- corresponds to --
{ ?subject ?property <http://pl.dbpedia.org/resource/Robin_Wright> }
You can get these with SPARQL queries like this, which will include all triples with that entity as object --
SELECT ?s ?p
WHERE
{ ?s ?p <http://pl.dbpedia.org/resource/Robin_Wright> }
-- or this, which will include all triples with that entity as subject and as object --
DESCRIBE <http://pl.dbpedia.org/resource/Robin_Wright>

Extract subparts using pattern matching in Sybase database

java.util.regex.Pattern p = java.util.regex.Pattern.compile("[\\)\\(\\+\\-\\*\\s]+");
String[] tokens;
try{ tokens = p.split(s); } catch (blah) { }
How can I accomplish the above functionality in select statement in Sybase ASE 15.0.3.
The Java class works but we are trying to avoid shuttling data in and out of DBMS.
select some_function(column1) from table1
I need some suggestion as to how this some_function may be implemented.
REGEXP and SIMILAR TO appear to be useful in the where clause. We want to extract portions of a colum which stores complex expressions.
Thank you

How can I change column name convention in Grails?

For now I have field "String firstName" it converted to "first_name" and i want "firstname" as default in Hibernate. Is it posible?
5.5.2.1 Table and Column Names
class Person {
String firstName
static mapping = {
table 'people'
firstName column:'firstname'
}
}
You can change the naming strategy for the entire project. From the documentation https://grails.github.io/grails-doc/latest/guide/GORM.html#customNamingStrategy.
By default Grails uses Hibernate's
ImprovedNamingStrategy to convert
domain class Class and field names to
SQL table and column names by
converting from camel-cased Strings to
ones that use underscores as word
separators. You can customize these on
a per-instance basis in the mapping
closure but if there's a consistent
pattern you can specify a different
NamingStrategy class to use.
Configure the class name to be used in grails-app/conf/DataSource.groovy in the hibernate section, e.g.
So, something like this in your DataSource.groovy
dataSource {
pooled = true
dbCreate = "create-drop"
…
}
hibernate {
cache.use_second_level_cache = true
…
naming_strategy = org.hibernate.cfg.DefaultNamingStrategy
}

Resources