private Collection<AssociationRoleIF> getTopicRoles(TopicIF topic, TopicIF roleType, TopicIF associationType) { if (roleType == null) { return topic.getRoles(); } else { if (associationType == null) { return topic.getRolesByType(roleType); } else { return topic.getRolesByType(roleType, associationType); } } }
/** * Get the the above/below rank role played by a given topic. * @param source The topic to get the rank role from. * @param up Indicates whether to get the role moving up or down in rank. * @return the the above/below rank role played by 'source'. */ private AssociationRoleIF getRankRole(TopicIF source, boolean up) { TopicIF sourceRoleType = up ? rankBelowRoleType : rankAboveRoleType; // Get the above/below rank role played by the given topic. Collection rankRoles = source.getRolesByType(sourceRoleType); if (rankRoles.size() != 1) { String nextTo = up ? "below" : "above"; if (rankRoles.isEmpty()) throw new OntopiaRuntimeException("Error in configuration: Missing" + " ranked " + nextTo + " role on configuration topic."); throw new OntopiaRuntimeException("Error in configuration: Found more" + " than one ranked " + nextTo + " role on configuration topic."); } AssociationRoleIF rankRole = (AssociationRoleIF)rankRoles.iterator() .next(); return rankRole; }
public static boolean hasBinaryAssociation(TopicIF player1, TopicIF aType, TopicIF rType1, TopicIF rType2) { for (AssociationRoleIF role : player1.getRolesByType(rType1, aType)) { AssociationIF assoc = role.getAssociation(); for (AssociationRoleIF role2 : assoc.getRoles()) if (!Objects.equals(role2, role) && role2.getType().equals(rType2)) return true; } return false; }
public static boolean hasBinaryAssociation(TopicIF player1, TopicIF aType, TopicIF rType1, TopicIF rType2) { for (AssociationRoleIF role : player1.getRolesByType(rType1, aType)) { AssociationIF assoc = role.getAssociation(); for (AssociationRoleIF role2 : assoc.getRoles()) if (ObjectUtils.different(role2, role) && role2.getType().equals(rType2)) return true; } return false; }
@Override public Set<Role> getRolesPlayed(Topic type) { Check.typeNotNull(type); return topicMap.wrapSet(wrapped.getRolesByType(topicMap.unwrapTopic(type))); }
@Override public Set<Role> getRolesPlayed(Topic type, Topic assocType) { Check.typeNotNull(type); if (assocType == null) { throw new IllegalArgumentException( "The association type must not be null"); } return topicMap.wrapSet(wrapped.getRolesByType(topicMap.unwrapTopic(type), topicMap.unwrapTopic(assocType))); }
public static boolean prefetchRolesByType(TopicMapIF tm, QueryMatches matches, int qmidx, TopicIF rtype, int[] fields, boolean[] traverse) { if (!doPrefetch(tm)) return false; // no prefetching if no hits if (matches.last < 0) return false; // NOTE: taking advantage of the fact that the // TopicIF.getRolesByType results are being cached // collect roles by type Collection roles = new CompactHashSet(); for (int row = 0; row <= matches.last; row++) { TopicIF topic = (TopicIF) matches.data[row][qmidx]; roles.addAll(topic.getRolesByType(rtype)); } // prefetch starting with roles return Prefetcher.prefetch(tm, roles, Prefetcher.AssociationRoleIF, fields, traverse); }
protected Set<TopicIF> fetchChildren(TopicMapIF topicmap, TopicIF topic) { TopicIF parentChildType = TopicMapPreferencesOntology.PARENTCHILD.t(topicmap); TopicIF parentType = TopicMapPreferencesOntology.PARENT.t(topicmap); TopicIF childType = TopicMapPreferencesOntology.CHILD.t(topicmap); TopicIF preferenceType = TopicMapPreferencesOntology.PREFERENCE.t(topicmap); Set<TopicIF> result = new HashSet<TopicIF>(); for (AssociationRoleIF role1 : revitalize(topic, topicmap).getRolesByType(parentType, parentChildType)) { for (AssociationRoleIF role2 : role1.getAssociation().getRolesByType(childType)) { TopicIF child = role2.getPlayer(); if (child.getTypes().contains(preferenceType)) { result.add(child); } } } return result; }
it = topic.getRolesByType(roletype).iterator(); } else it = topic.getRoles().iterator();
public void testTypeHoistUnapplicable2() throws InvalidQueryException, IOException { load("assocs.ltm"); TopicIF lmg = getTopicById("lmg"); TopicIF employee = getTopicById("employee"); List matches = new ArrayList(); addMatch(matches, "A", lmg.getRolesByType(employee).iterator().next()); verifyQuery(matches, "/* #OPTION: optimizer.reorder = false */ " + "type($A, employee), role-player($A, lmg)?"); }
public void testRolesByType() { TopicIF type = builder.makeTopic(); assertTrue("roles by non-existent type initially not empty", topic.getRolesByType(type).size() == 0); AssociationIF assoc = builder.makeAssociation(builder.makeTopic()); // builder adds role to assoc AssociationRoleIF role = builder.makeAssociationRole(assoc, type, topic); assertTrue("roles of correct type not found", topic.getRolesByType(type).size() == 1); // builder adds role to assoc TopicIF other = builder.makeTopic(); TopicIF rtype = builder.makeTopic(); AssociationRoleIF role2 = builder.makeAssociationRole(assoc, rtype, other); assertTrue("role with no type found", topic.getRolesByType(type).size() == 1); assertTrue("role with no type not found", other.getRolesByType(rtype).size() == 1); }
public VizTopicTypePriorityConfigManager( VizTopicMapConfigurationManager tmConfig) { this.tmConfig = tmConfig; rankTopic = tmConfig.getTopic(RANK_TOPIC); defaultTypePrecedenceTopic = tmConfig.getTopic(DEFAULT_TYPE_PRECEDENCE_TOPIC); rankAssociationType = tmConfig.getTopic(RANK_ASSOCIATION); rankAboveRoleType = tmConfig.getTopic(RANK_ABOVE_ROLE); rankBelowRoleType = tmConfig.getTopic(RANK_BELOW_ROLE); if (rankTopic.getRolesByType(rankBelowRoleType).isEmpty()) { // Initialize the priority circuit with rankTopic. AssociationIF newRankAssociation = tmConfig.builder.makeAssociation(rankAssociationType); tmConfig.builder.makeAssociationRole(newRankAssociation, rankBelowRoleType, rankTopic); tmConfig.builder.makeAssociationRole(newRankAssociation, rankAboveRoleType, rankTopic); } if (!isRanked(defaultTypePrecedenceTopic)) rankLast(defaultTypePrecedenceTopic); }
for (AssociationRoleIF arole : topic.getRolesByType(rtype, type)) {
assertTrue("p1.rolesByType(rt1,at1).size is not 1.", p1.getRolesByType(rt1, at1).size() == 1); assertTrue("p1.rolesByType(rt2,at1).size is not 0.", p1.getRolesByType(rt2, at1).size() == 0); assertTrue("p2.rolesByType(rt1,at1).size is not 0.", p2.getRolesByType(rt1, at1).size() == 0); assertTrue("p2.rolesByType(rt2,at1).size is not 1.", p2.getRolesByType(rt2, at1).size() == 1); assertTrue("p1D.rolesByType(rt1,at1).size is not 1.", p1D.getRolesByType(rt1D, at1D).size() == 1); AssociationRoleIF r1E = (AssociationRoleIF)p1E.getRolesByType(rt1E, at1E).iterator().next(); r1E.getAssociation().setType(at2E); r1E.setType(rt3E); assertTrue("p1E.rolesByType(rt1,at1).size is not 0.", p1E.getRolesByType(rt1E, at1E).size() == 0); assertTrue("p1E.rolesByType(rt1,at2).size is not 0.", p1E.getRolesByType(rt1E, at2E).size() == 0); assertTrue("p1E.rolesByType(rt3,at2).size is not 1.", p1E.getRolesByType(rt3E, at2E).size() == 1); assertTrue("p2E.rolesByType(rt2,at2).size is not 1.", p2E.getRolesByType(rt2E, at2E).size() == 1); TopicIF at1B = (TopicIF)tmB.getObjectById(oid_at1); TopicIF at2B = (TopicIF)tmB.getObjectById(oid_at2); assertTrue("p1B.rolesByType(rt3,at2).size is not 1.", p1B.getRolesByType(rt3B, at2B).size() == 1); assertTrue("p1B.rolesByType(rt3,at1).size is not 0.", p1B.getRolesByType(rt3B,at1B).size() == 0); assertTrue("p1B.rolesByType(rt3,at2).size is not 1.", p1B.getRolesByType(rt3B,at2B).size() == 1); assertTrue("p1B.rolesByType(rt1,at1).size is not 0.", p1B.getRolesByType(rt1B,at1B).size() == 0); assertTrue("p1B.rolesByType(rt1,at2).size is not 0.", p1B.getRolesByType(rt1B,at2B).size() == 0); assertTrue("p1B.rolesByType(rt2,at1).size is not 0.", p1B.getRolesByType(rt2B,at1B).size() == 0); assertTrue("p1B.rolesByType(rt2,at2).size is not 0.", p1B.getRolesByType(rt2B,at2B).size() == 0); assertTrue("p2B.rolesByType(rt2,at1).size is not 0.", p2B.getRolesByType(rt2B,at1B).size() == 0); assertTrue("p2B.rolesByType(rt2,at2).size is not 1.", p2B.getRolesByType(rt2B,at2B).size() == 1);
assertTrue("p2.roles.size is not 1.", p2.getRoles().size() == 1); assertTrue("p1.rolesByType(rt1).size is not 1.", p1.getRolesByType(rt1).size() == 1); assertTrue("p1D.rolesByType(rt1).size is not 1.", p1D.getRolesByType(rt1D).size() == 1); assertTrue("p1B.rolesByType(rt1).size is not 1.", p1B.getRolesByType(rt1B).size() == 1); r1B.setPlayer(tmB.getBuilder().makeTopic()); assertTrue("p1B.roles.size is not empty.", p1B.getRoles().size() == 0); assertTrue("p1B.rolesByType(rt1B).size is not 0.", p1B.getRolesByType(rt1B).size() == 0); assertTrue("p1C.rolesByType(rt1).size is not 0.", p1C.getRolesByType(rt1C).size() == 0);