Get Requirement Relation Types with P4C

I’m attempting to get the type of relation between a requirement and a function with p4c. I’m able to get the source and target, but the “get_relation_type” function doesn’t seem to be working, it’s returning an empty list. Any thoughts on what I’m missing?

This is my sample architecture…
image

Here are the properties of one of the relation objects…

This is the AbstractRelation class…

This is my code…
image

And this is my result…
image

It’s most likly the requirement button not toggled in the semantic browser view. The method calls the query from the semantic browser.

requierment.semantic.browser

But if you are using a version before 1.3.0 it can be an issue with the __str__ of the JavaList class. In this case you can try to iterate over it to make sure it’s empty or not.

1 Like

Interesting! I did not have requirements shown in the semantic browser. I didn’t know that was an option, and it’s actually helpful for many reasons, so thanks for pointing that out!

However, I am using 1.3.0 and I was still getting an empty list after showing requirements in the semantic browser. I followed your advice and iterated over it to pull out the single type and was able to get the value, so thanks for that guidance as well.

Do you have any idea if it’s possible to query it in a way that doesn’t require enabling that view in the semantic browser? Or if it is possible to enable that “show requirements in semantic browser” setting through the script itself? I’m trying to build out some common scripts that I’d like for multiple team members to be able to execute, and I can forsee issues with people not realizing that setting has to be enabled to run the script. Of course I’ll include some notes in the script itself, but I’m thinking about error proofing.

The query is implemented by the requirement addon developers… So you can have a look to the Java code and see if there is an other way to call an API to get this list or you can re-implement the logic in Python.

I thought the toggle state of the button was saved in the workspace but it’s not… So calling the query is not an option for Python4Capella:

I probably won’t work on this soon unless you reach Obeo for commercial support. But if you work on this on your side feel free to submit a pull request or share your implementation here.

1 Like