phenoscape / scowl

A Scala DSL for programming with the OWL API.
MIT License
54 stars 8 forks source link

Infix conjuctions are not commutative #10

Open phillord opened 7 years ago

phillord commented 7 years ago

Conjuction is commutative in OWL, but not in Scowl. Consider:

scala> import org.phenoscape.scowl._

import org.phenoscape.scowl._

scala>
scala> val a = Class("a")
a: org.semanticweb.owlapi.model.OWLClass = <a>

scala> val b = Class("b")
b: org.semanticweb.owlapi.model.OWLClass = <b>

scala> val c = Class("c")
c: org.semanticweb.owlapi.model.OWLClass = <c>

scala> a and b and c
res0: org.semanticweb.owlapi.model.OWLObjectIntersectionOf = ObjectIntersectionOf(<a> <b> <c>)

scala> a and (b and c)
res1: org.semanticweb.owlapi.model.OWLObjectIntersectionOf = ObjectIntersectionOf(<a> ObjectIntersectionOf(<b> <c>))

scala> (b and c) and a
res2: org.semanticweb.owlapi.model.OWLObjectIntersectionOf = ObjectIntersectionOf(<a> <b> <c>)

All of these results make sense except for the last which should return ObjectIntersectionOf(<a> ObjectIntersectionOf(<b> <c>)) I think.

I think this is caused bc2d369 which addresses #3 unfortunately.

Just playing with Scowl and Scala. Very nice piece of work (Scowl that is, Scala I will reserve judgement on for the moment)

balhoff commented 7 years ago

Thanks for the report! In the spirit of #3 I would be inclined to change a and (b and c) to return ObjectIntersectionOf(<a> <b> <c>). I don't think there is a way to distinguish a and b and c from (a and b) and c in the code being called, since the parentheses just match the normal Scala order of operations. Does this sound okay for the "Manchester" syntax? The functional style is still available for creating nested intersections of unions.

phillord commented 7 years ago

shrugs. Six to one, half a dozen to the other. You trading off the gain in commutativity for the loss of non-associativity.

Can you not overload the and method to deal specifically with an OWLObjectIntersection to not use asConjunctSet. I guess that would work but would break A and B and C and D.

I don't have this problem in tawny, cause I use prefix notation. But then I can't do A and B or C so nicely.