generating less methods for functional properties and properties with range = boolean

41 views
Skip to first unread message

Jan Polowinski

unread,
Oct 29, 2013, 6:33:34 AM10/29/13
to semw...@googlegroups.com
Hi all,

I'm starting to use RDFreactor and wonder whether there is there a way to reduce the number of methods that are generated for a property when this property is functional or has a boolean range. I found that 13 methods are generated (without the static ones) for such a property to handle the addition and removal to/from collections.

Is there a way to configure this or change/improve the ontology to get the desired result? Actually (maybe this is naive), I would just like to have 2 methods for boolean-range-properties  - sth like:

void setSomeBooleanProperty(Boolean newValue) {}
Boolean isSomeBooleanProperty() {}

Would it make sence for me to look at the Velocity templates and try to tweek them?

Thank you for any advice!
Jan

Roland Stühmer

unread,
Oct 29, 2013, 5:08:05 PM10/29/13
to semw...@googlegroups.com
Hi Jan!


Jan Polowinski wrote:
Is there a way to configure this or change/improve the ontology to get the desired result? Actually (maybe this is naive), I would just like to have 2 methods for boolean-range-properties  - sth like:

void setSomeBooleanProperty(Boolean newValue) {}
Boolean isSomeBooleanProperty() {}

Something along these lines happens (e.g., all the *add*SomeBooleanProperty() method are omitted) if you model your RDFS property with owl:maxCardinality "1" or owl:cardinality "1" as follows:

:someBooleanProperty
      rdf:type owl:FunctionalProperty , owl:DatatypeProperty ;
      rdfs:domain <yourClass> ;
      rdfs:range xsd:boolean ;
      owl:maxCardinality "1" .


 
Would it make sence for me to look at the Velocity templates and try to tweek them?

If the above is not enough reduction, then you should have a look at the templates, yes!

Best!

Roland.

Jan Polowinski

unread,
Oct 30, 2013, 8:13:37 PM10/30/13
to semw...@googlegroups.com
Hello Roland,

thank you for your quick answer. One note and two more short questions:


Is there a way to configure this or change/improve the ontology to get the desired result? Actually (maybe this is naive), I would just like to have 2 methods for boolean-range-properties  - sth like:

void setSomeBooleanProperty(Boolean newValue) {}
Boolean isSomeBooleanProperty() {}

Something along these lines happens (e.g., all the *add*SomeBooleanProperty() method are omitted) if you model your RDFS property with owl:maxCardinality "1" or owl:cardinality "1" as follows:

:someBooleanProperty
      rdf:type owl:FunctionalProperty , owl:DatatypeProperty ;
      rdfs:domain <yourClass> ;
      rdfs:range xsd:boolean ;
      owl:maxCardinality "1" .


I was able to reduce the number of methods from 13 to 10, though still some add... methods are generated. (If this should not be the case, I can provide a complete code sample)
Are you sure, owl:maxCardinality may be used directly (globally) on properties? I only used it in restrictions such as:

:Mapping a owl:Class ;
      rdfs:subClassOf
              [ rdf:type owl:Restriction ;
                owl:maxCardinality "1" ;
                owl:onProperty :fallsBackTo
              ] ;

Do I need to use the latest version of RDFReactor (4.8.3)? I'm currently on 4.7.0, since I got some NoClassDefFoundErrors (e.g. org/apache/commons/io/input/BOMInputStream) when using the latest, I guess I need to add some more dependencies manually.

Best regards!

Jan

Roland Stühmer

unread,
Nov 2, 2013, 3:52:22 AM11/2/13
to semw...@googlegroups.com
Hello Jan!


Jan Polowinski wrote:
I was able to reduce the number of methods from 13 to 10, though still some add... methods are generated. (If this should not be the case, I can provide a complete code sample)

I think for properties with "cardinality <= 1" this should be fixed. All "add..." methods should be only generated for higher-cardinality properties.
 
Are you sure, owl:maxCardinality may be used directly (globally) on properties? I only used it in restrictions such as:

:Mapping a owl:Class ;
      rdfs:subClassOf
              [ rdf:type owl:Restriction ;
                owl:maxCardinality "1" ;
                owl:onProperty :fallsBackTo
              ] ;

You are right, from the OWL modelling point this is wrong. Have you tried both ways (using restrictions and using the property directly) in RDFReactor?

 
Do I need to use the latest version of RDFReactor (4.8.3)? I'm currently on 4.7.0, since I got some NoClassDefFoundErrors (e.g. org/apache/commons/io/input/BOMInputStream) when using the latest, I guess I need to add some more dependencies manually.

Yes, you should use the latest version. There is even a 4.8.4-SNAPSHOT [1] (with newer Jena and Sesame dependencies). Using Maven I have not seen dependency problems. Can you use Maven?


Best regards,

Roland.

[1] http://mavenrepo.fzi.de/semweb4j.org/snapshots/org/semweb4j/rdfreactor.dist/

Jan Polowinski

unread,
Nov 2, 2013, 6:48:38 AM11/2/13
to semw...@googlegroups.com
.. again to the mailinglist and now including the mentioned screenshot ...

---------- Forwarded message ----------
From: Jan Polowinski <jan.pol...@googlemail.com>
Date: 2013/11/2
Subject: Re: [semweb4j] Re: generating less methods for functional properties and properties with range = boolean
To: Roland Stühmer <ma...@roland-stuehmer.de>


Hello Roland,

I think the cardinality statements  thar reactor requires can be added temporarily to the model when this helps the code generation, so this is fine for now. However, even when I did this, still some "add..." methods are generated. Below I attach a complete minimum example which still generates 11 methods including 2x "add..." and 2x "getAll.." when I use (only) owl:cardinality instead of owl:cardinality I get one more method "removeAll..." (cf. attached screenshot). Do I have to use rdfsAndOwl resoning to make rdfRecator consider the constraints? I only use rdfs resoning at the moment, because otherwise I get the an error (see bottom of the mail). Maybe you can have a short look at the code, we could live with the additional methods, but it would be great to get rid of them for reasons of more readable code.

The dependency problems are now solved, I'm not sure what went wrong here at first. 4.8.3 is running fine now.

######### EXAMPLE RDF ########################

@prefix :        <http://purl.org/rvl/> .
@prefix owl:     <http://www.w3.org/2002/07/owl#> .
@prefix rdf:     <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#> .
@prefix viso-graphic:  <http://purl.org/viso/graphic/> .
@prefix xsd:     <http://www.w3.org/2001/XMLSchema#> .

:     rdf:type owl:Ontology ;
      rdfs:label "RDF Visualization Language (RVL)"^^xsd:string .

:Mapping
      rdf:type owl:Class ;
      rdfs:label "Mapping"^^xsd:string ;

      rdfs:subClassOf
              [ rdf:type owl:Restriction ;
                owl:cardinality "1" ;
               owl:onProperty :fallsBackTo
             ] .

:fallsBackTo
      rdf:type owl:ObjectProperty, owl:FunctionalProperty ;
      rdfs:domain :Mapping ;
      rdfs:range :Mapping ;
      owl:maxCardinality "1" ;
      owl:cardinality "1" ;
      owl:minCardinality "1" .

########### EXAMPLE GENERATOR CALL ##########

public static void main(String[] args) throws Exception {
        CodeGenerator.generate(
                ONTOLOGY_URL,
                PATH_FOR_GEN_CODE,
                PACKAGE,
                Reasoning.rdfs,
                true
                );
       
    }

######### ERROR WHEN USING RDFSANDOWL REASONING ######

INFO : loading from /Users/Jan/VersionControlRepositories/git/rvl/org.purl.rvl.vocabulary/rvl-small.n3 at org.ontoware.rdfreactor.generator.CodeGenerator.(CodeGenerator.java:185)
INFO : using semantics: rdfsAndOwl at org.ontoware.rdfreactor.generator.CodeGenerator.(CodeGenerator.java:147)
INFO : MODEL generating RDFS+OWL mix semantics into /Users/Jan/VersionControlRepositories/git/rvl/org.purl.rvl.tooling.codegen.rdfreactor/src/main/java ... at org.ontoware.rdfreactor.generator.CodeGenerator.(CodeGenerator.java:160)
INFO : Initialising JModel at org.ontoware.rdfreactor.generator.ModelGenerator.(ModelGenerator.java:181)
INFO : Loading schema triples at org.ontoware.rdfreactor.generator.ModelGenerator.(ModelGenerator.java:184)
INFO : Skolemisation (replacing all blank nodes with random URIs) at org.ontoware.rdfreactor.generator.ModelGenerator.(ModelGenerator.java:189)
INFO : Add mapping from OWL to RDF at org.ontoware.rdfreactor.generator.ModelGenerator.(ModelGenerator.java:192)
DEBUG: MODEL after inferencing, found 198 statements at org.ontoware.rdfreactor.generator.ModelGenerator.(ModelGenerator.java:202)
INFO : Creating a class called 'Thing1' for all properties with no given domain at org.ontoware.rdfreactor.generator.ModelGenerator.(ModelGenerator.java:206)
DEBUG: CLASS http://www.w3.org/1999/02/22-rdf-syntax-ns#Property is known -> skipping generation at org.ontoware.rdfreactor.generator.ModelGenerator.(ModelGenerator.java:219)
DEBUG: CLASS http://www.w3.org/1999/02/22-rdf-syntax-ns#List is known -> skipping generation at org.ontoware.rdfreactor.generator.ModelGenerator.(ModelGenerator.java:219)
DEBUG: CLASS http://www.w3.org/2000/01/rdf-schema#Resource is known -> skipping generation at org.ontoware.rdfreactor.generator.ModelGenerator.(ModelGenerator.java:219)
DEBUG: CLASS http://www.w3.org/2000/01/rdf-schema#Class is known -> skipping generation at org.ontoware.rdfreactor.generator.ModelGenerator.(ModelGenerator.java:219)
DEBUG: CLASS http://www.w3.org/1999/02/22-rdf-syntax-ns#Statement is known -> skipping generation at org.ontoware.rdfreactor.generator.ModelGenerator.(ModelGenerator.java:219)
DEBUG: CLASS http://www.w3.org/2000/01/rdf-schema#Literal is known -> skipping generation at org.ontoware.rdfreactor.generator.ModelGenerator.(ModelGenerator.java:219)
DEBUG: CLASS http://www.w3.org/1999/02/22-rdf-syntax-ns#Alt is known -> skipping generation at org.ontoware.rdfreactor.generator.ModelGenerator.(ModelGenerator.java:219)
DEBUG: CLASS http://www.w3.org/1999/02/22-rdf-syntax-ns#Bag is known -> skipping generation at org.ontoware.rdfreactor.generator.ModelGenerator.(ModelGenerator.java:219)
DEBUG: CLASS http://www.w3.org/2002/07/owl#Ontology is known -> skipping generation at org.ontoware.rdfreactor.generator.ModelGenerator.(ModelGenerator.java:219)
DEBUG: NAME     <blank://1> found no label. Using 'A_1' computed from URI. at org.ontoware.rdfreactor.generator.JavaNamingUtils.(JavaNamingUtils.java:55)
DEBUG: CLASS A_1 generated for <blank://1> ... at org.ontoware.rdfreactor.generator.ModelGenerator.(ModelGenerator.java:227)
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    at java.util.ArrayList.rangeCheck(ArrayList.java:604)
    at java.util.ArrayList.get(ArrayList.java:382)
    at org.ontoware.rdfreactor.generator.ModelGenerator.createFromRDFS_AND_OWL(ModelGenerator.java:230)
    at org.ontoware.rdfreactor.generator.CodeGenerator.generate(CodeGenerator.java:162)
    at org.ontoware.rdfreactor.generator.CodeGenerator.generate(CodeGenerator.java:77)
    at org.ontoware.rdfreactor.generator.CodeGenerator.generate(CodeGenerator.java:54)
    at generator.TestReactor.main(TestReactor.java:27)

###########################################

Best regards and thank you again,
Jan

2013/11/2 Roland Stühmer <ma...@roland-stuehmer.de>

--
You received this message because you are subscribed to the Google Groups "RDF2Go and RDFReactor (part of semweb4j)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to semweb4j+u...@googlegroups.com.
To post to this group, send email to semw...@googlegroups.com.
Visit this group at http://groups.google.com/group/semweb4j.
For more options, visit https://groups.google.com/groups/opt_out.


Bildschirmfoto 2013-11-02 um 11.21.43.png

Roland Stühmer

unread,
Nov 5, 2013, 5:03:43 PM11/5/13
to semw...@googlegroups.com, jan.pol...@googlemail.com
Hi Jan, all!


Jan Polowinski wrote:
I think the cardinality statements  thar reactor requires can be added temporarily to the model when this helps the code generation, so this is fine for now. However, even when I did this, still some "add..." methods are generated. Below I attach a complete minimum example which still generates 11 methods including 2x "add..." and 2x "getAll.." when I use (only) owl:cardinality instead of owl:cardinality I get one more method "removeAll..." (cf. attached screenshot). Do I have to use rdfsAndOwl resoning to make rdfRecator consider the constraints? I only use rdfs resoning at the moment, because otherwise I get the an error (see bottom of the mail). Maybe you can have a short look at the code, we could live with the additional methods, but it would be great to get rid of them for reasons of more readable code.

I just had a look at some generated code. It turns out the add...() methods are generated for cardinality=1 nevertheless but they are set to throw "CardinalityException" after you use them more often. So the design decision seems to have been: to always have the add methods in the API...

If you can spend some time on the tempates, I would be fine with a change for a new release! After all, these APIs are for human users, so simplicity (and not generality) seems important.

Roland.

Reply all
Reply to author
Forward
0 new messages