Declare multiple objects in one definition - xtext

I am new to Xtext and I would like to be able to have declarations like
class A, B, C{
Some common features
}
and be able to refer to A, B and C.
I tried to do it like 'class' name +=ID (',' name += ID)* but this wont work since no object are apparently created. I assume I have to use actions but I don't understand how. Can anyone help me?

Related

Esper query for A followed by B immediately without any other events in between (no matter which event)

I have to implement the rule, that if A occurs, B hast to occur next without any event in between. Usually I could do this by just using the patter:
A->(B and not ...)
But I have to implement it very dynamical. That means that I don't know all of the possible events in advance. Does anybody know how i could implement this?
I guess I need something like:
A->(B and not any other event)
Thank you for your help. :)
See this other ticket Esper statement to check, if A is followed by B without any other As in between
It explains the match-recognize.
Here are a few path you can go down in respect to many types of events.
Create-schema with inherits plus typeof-function
create schema Parent();
create schema A() inherits Parent;
create schema B() inherits Parent;
// now you can treat all events as Parent events
select * from pattern[p=Parent(typeof(p)='A') -> ...] // or match-recognize
Variant stream
create variant schema AnyEventStream as *; // this stream can hold any type of event
insert into AnyEventStream select * from A;
insert into AnyEventStream select * from B;
select * from pattern[p=AnyEventStream(typeof(p)='A') -> ...] // or match-recognize
Normalize with insert-into
insert into CombinedStream select 'a' as type from A;
insert into CombinedStream select 'b' as type from B;
// now match on CombinedStream
select * from pattern[p=CombinedStream(type='A') -> ...] // or match-recognize
Make each event a column
create schema CombinedStream(col java.lang.Object);
insert into CombinedStream select a as col from A as a;
insert into CombinedStream select b as col from B as b;
select * from pattern[p=CombinedStream(typeof(col)='...') -> ...] // or match-recognize
You can probably combine some of these approaches. You can also use Java interfaces and abstract classes in replacement of "inherits" since the type system recognizes superclasses/interfaces.
Thank you very for your reply. I tried your suggestions and making each event a column seams to work pretty well for me.
My only problem is, that i have to get access to the properties of each event to check some conditions.
For example:
select * from CombinedStream.win:length(1) where typeof(col)='MachineFailureEvent' and id=1;
Until the id-check everything works fine, but the compiler tells me, that the property id is not valid in this stream.. do you have in idea?
Tanke you :)

Protege issue: Object property assertion for a class in ontology

if I have the same object property value "val1" for all instances of "class1" in ontology, how can I infer that object property value for that "class1" is "val1"
Just to make this more clear to talk about, say you have Class1 and the object property property1. We further assume for Class1 the only explicitly specified instances are c1, c2 and c3. Further we have that:
property1(c1, val1)
property1(c2, val1)
property1(c3, val1)
Now due to your known c1...c3 instances being linked via property1 to val1, you want to infer that when property1(x,y) where x is of type Class1, it must follow that y = val1.
Due to the open world assumption, the possibility exist that another instance, say c4, can exist that is of type Class1 that is related via property1 to val2. Hence a reasoner will not be able to do this inference.
You could use rules though to do this. With SWRL you can state Class1(?x) => property1(?x, ?val1). This states whenever you have an instance of Class1 it is linked to val1 via property1.

In Jena API, How to count how many individuals of a class using Jena RULE?

I want to get how many individuals of a class. For example, for the Person class, there is A, B, C. I tried to count it using the following rule:
[r3: (?p rdf:type hv:Person),(?classx1 hv:hasvalue ?n),addOne(?n,?new)
-> drop(1),(?class1 hv:hasvalue ?new)
]
However, it was fired in a closed loop since the (?class1 hv:hasvalue ?new) will change each time. I dont like to introduce SPARQL.
What I do to count individuals is :
OntModel model;
Resource individual = model.getResource("http://www.w3.org/2002/07/owl#NamedIndividual"));
Property property = model.getProperty("http://www.w3.org/1999/02/22-rdf-syntax-ns#type");
ResIterator iterator = infModel.listResourcesWithProperty(property, individual) ;
int count = Iterators.size(iterator);
Last line is possible because of Guava Library.
It can be improved but still a solution.
More information and corrections in the comments. Thanks to #ssz.

How do I create a Grails query for a many-to-many using primitives?

I have a POGO we'll call Foo and it has a list of Bars. In the database, these are simple integers, but they're stored in a separate table (Foo_Bars)
class Foo {
String name
...
static hasMany = [bars:Integer]
...
}
So my question is, how do I create a query to find all Foos that with bars that are in a list. I know how I would write it in SQL.
SELECT * FROM foo, foo_bars
WHERE foo.id = foo_bars.foo_id
AND foo_bars.bars_integer IN (11, 15, 52)
But I figure there must be a simpler way, using GORM or HQL. How would I write this?
but what exactly you want to achieve? list of Foo's where bars is equal to (11,15,52), or ONE OF bars is in the list or the list of bars contain each of given list?
either way, I doubt you can do it in criteria or using a dynamic finder, I'm trying to do it in an unit test and nothing worked
I would go with creating another domain class like
class FooBar {
Foo foo
Integer integer
}
which would create exactly the same database table as you already have, and then querying would be much simpler

grails gorm hasMany query based on select options from a gsp page

I have the following scenario,
Domain class A which hasMany B's
Domain class B which hasMany C's and belongsTo A
Domain class C which belongsTo B
Class E {
A a
B b
C c
}
Class C {
String name
}
I want to query E values i.e get a list of some E property eg in this case c.name based on values selected by a user in a select box, i.e user selects A and B from multiple select boxes and based on this criteria, a list of names is obtained.
in other words i want to find all names in c which satisfy condition set by a and b
have tried to figure out the GORM query to no avail.
thanks
I solved this by using raw SQL joins. Not really certain if this was the best way but it worked for me.
I got the parameters from A and B, ie
def fromA = params.someCriteriaValueInA
def fromB = params.someCriteriaValueInB
Please note that these are fetched from a gsp. Also, fromB values would be loaded based on fromA values, using chained selects.
In the grails controller/service ...
def db = new Sql(dataSource)
def result = db.rows("your sql to go here")
Then you can do whatever you want with the results, for example manipulate it in a template
render(template: "myResults", model:[result :result])
Dont forget to inject the dataSource bean in your controller/service, and also doing the necessary import
import groovy.sql.Sql
Please note that this involved traversing many domain class instances, and for those who like raw SQL this would seem easier.Would appreciate a different approach, maybe using GORM's criteria.

Resources