Roles (query directive)

From WandoraWiki
Jump to: navigation, search

Description

Returns the input row but with only the specified roles. If a role is not found in input, it is added with null value.

Constructor

Roles(String s1,...)

Examples

Roles is typically used to remove columns that are needed inside the query but not necessarily wanted for the final result. For example, following query finds which instance of the input are also subclasses of it. Without the Roles directive it would have three columns "#instances", XTMPSI.SUPERCLASS and the default column which is the initial input topic. "#instances" and XTMPSI.SUPERCLASS are always the same topic because we're only looking for rows where this is the case. But we don't need to see this same topic twice. Also we don't usually really need to see the input topic either. So we can use Roles directive to remove everything else but "#instance" which contains all we need to see.

importPackage(org.wandora.query2);
importPackage(org.wandora.topicmap);
new Roles("#instance").from(
  new Join(
    new Instances().as("#instance"),
    new Players(
      XTMPSI.SUPERCLASS_SUBCLASS,
      XTMPSI.SUBCLASS).whereInputIs(XTMPSI.SUPERCLASS)
  ).where("#instance","t=",XTMPSI.SUBCLASS)
)
Personal tools