Is there any "eInverse()" method in P4C? If No, how to get it?

Hello,
I was experimenting with the interpreter AND the with my script at the time,
The interpreter worked fine, I applied an eInverse() function to a capella function and I obtained many results.
I went ahead and I applied to the same capella function, saved inside a java object variable, the function eInverse or einverse, but none worked:

a=se.get_all_contents_by_type(SystemFunction)[1]
print("new method testing")
print(a)
print(a.get_java_object())
#===> Result: org.polarsys.capella.core.data.ctx.impl.SystemFunctionImpl@4196ccdb (id: 08559f95-ae1....
#print(a.get_java_object().eInverse()) 
#====> Result: py4j.Py4JException: Method eInverse([]) does not exist
print(a.get_java_object().einverse()) 
#====> Result: py4j.Py4JException: Method einverse([]) does not exist

As you can see above (a.get_java_object()) is a java object, yet, the eInverse functions would not work.
Is there any way how to achieve / apply this function ?

Thanks

The einverse() you are using in the interpeter is an AQL service. But there is an equivalent in Python4Capella:

e_inverse(e_obj, reference_name)

for instance:

e_inverse(object.get_java_object(), "type")

This will only returns object that can be wrapped in a class form the Python API.

1 Like

Hello Yvan,
When you write “type” is it the class?
Like when I want to get the inverse of a system function:

I would have to write this:

print(e_inverse(a, "ctx::SystemComponent")
#with a="#org.polarsys.capella.core.data.ctx.impl.SystemFunctionImpl@5e07662b (id: 08.."

I am getting only EMPTY LISTS results:

[]

Am I wrong about writing the type I suppose?
Or it is somehow the fact that this service provides a “SET”, making python not able to extract its content and it into the list… that stays empty?
Thanks


Seconde question: isn’t it possible to get to use a “e_inverse()” with only one parameter (without having to tell what is the type you are searching, in the interpreter, the aql service allows use to get all inverse outputs if we don’t use a parameter)

Thanks and good day/evening

“type” is the name of an EReference, in this case you can pass a Class as first parameter of e_inverse() and it will return all objects referencing the class using an EReference named “type”. That was not the best example I guess.

And for the moment only the e_inverse() with an EReference name is supported. I opened the following issue:

Very sorry Yvan,
I still don’t get it.

  • How do I find the name of the EReference between my sys function and the system object? (cf. screen shot of the asl interpreter, it’s between the function “Gather 3” and The System)
    Analysing some Ecores and knowing but of SysML I suppose it’s simply the “reference”, or name of the object which whome there is an “association” link, right?

  • You say I can use the EReference as my first parameter (it means i have to inverse the function to [[e_inverse(“type”, object.get_java_object())?]]

  • You also mention it returning “all objects referencing the class”, not quite sure to see the picture, since I am applying it one single object hopefully (unless you are talking about the result)
    Sorry still a bit lost, could you enlighten me a bit more?

Great!

I will try with an other example. Let say we have a PhysicalComponent and want to get its parent you could use:

 parent = e_inverse(myPhysicalComponent, "ownedPhysicalComponents")

It navigates the ownedPhysicalComponents EReference in the opposite direction. So in your case you need to get the EReference in the SystemFunction EClass that reference the EClass of the “system object”. The you can use the name of the reference an pass the “system object” as parameter to get the instance of SystemFunction you are looking for.

1 Like

This is interesting, I get it now, yes it the name we insert at the end of an association in the class diagram in UML/sysML (and I guess it’s the reference between 2 classes in multi oriented object paradigm programming),
Like this:

Ok now I think I found the answer to 'how to know what is the name of the ‘type/EREF’" to use, the answer is a parameter applied to an eClass() output that allows us to get all ERefs.


Edit: Nevermind, it worked out! (I think).
Thanks a lot

1 Like