public TopicAssocDep(TopicMapIF tm) throws NullPointerException { this.tm = tm; associations = new HashMap(); traverse(tm.getAssociations()); }
@Override public Set<Association> getAssociations() { return wrapSet(wrapped.getAssociations()); }
@Override public int getAssociationCount() { return transaction.getTopicMap().getAssociations().size(); }
protected static void removeDuplicates(TopicMapIF tm) { Map keymap = new HashMap(); AssociationIF[] assocs = new AssociationIF[tm.getAssociations().size()]; tm.getAssociations().toArray(assocs); for (int i=0; i < assocs.length; i++) { AssociationIF assoc = assocs[i]; String key = KeyGenerator.makeAssociationKey(assoc); if (keymap.containsKey(key)) { System.out.println("Removing: " + key); // If map contains key remove this association assoc.remove(); } else { keymap.put(key, null); } } }
public void count() throws NullPointerException { Collection topics, assocs, occurs; topics = tm.getTopics(); assocs = tm.getAssociations(); Iterator it = topics.iterator(); while (it.hasNext()) { TopicIF topic = (TopicIF)it.next(); occurs = topic.getOccurrences(); numberOfOccurrences += occurs.size(); } numberOfAssociations = assocs.size(); numberOfTopics = topics.size(); }
@Override public QueryMatches satisfy(QueryMatches matches, Object[] arguments) throws InvalidQueryException { int associx = matches.getIndex(arguments[0]); if (matches.data[0][associx] == null) return PredicateUtils.collectionToOne(matches, topicmap.getAssociations().toArray(), associx, associx, PredicateUtils.NO_OPERATION); else return PredicateUtils.filterClass(matches, associx, AssociationIF.class); } }
public void testCompletelyOpen() throws InvalidQueryException, IOException { load("family2.ltm"); List matches = new ArrayList(); Iterator it = topicmap.getAssociations().iterator(); while (it.hasNext()) addMatch(matches, "TOPIC", it.next()); verifyQuery(matches, "association($TOPIC)?"); }
@Override public void delete(boolean force) throws NotRemovableException { // Do nothing except closing the store, since we do not know how // to delete the topic map here. Implementations have to implement // deletion themselves. TopicMapIF tm = getTopicMap(); if (!force) { // If we're not forcing, complain if the topic map contains any data. if (!tm.getTopics().isEmpty()) throw new NotRemovableException("Cannot delete topic map when it contains topics."); if (!tm.getAssociations().isEmpty()) throw new NotRemovableException("Cannot delete topic map when it contains associations."); } // Remove all the objects from the topic map tm.clear(); close(); deleted = true; }
public void testAssociations() { // STATE 1 assertTrue("association set not empty initially", tm.getAssociations().size() == 0); // STATE 2 AssociationIF association = builder.makeAssociation(builder.makeTopic()); // added by builder assertTrue("association not added", tm.getAssociations().size() == 1); assertTrue("association identity not retained", tm.getAssociations().iterator().next().equals(association)); // STATE 2 association.remove(); assertTrue("association not removed", tm.getAssociations().size() == 0); // verify that it's safe association.remove(); }
public void testCompletelyOpen() throws InvalidQueryException, IOException { load("bb-test.ltm"); List matches = new ArrayList(); Iterator it = topicmap.getAssociations().iterator(); while (it.hasNext()) { AssociationIF assoc = (AssociationIF) it.next(); Iterator it2 = assoc.getRoles().iterator(); while (it2.hasNext()) { AssociationRoleIF role = (AssociationRoleIF) it2.next(); addMatch(matches, "PLAYER", role.getPlayer(), "ROLE", role); } } verifyQuery(matches, "role-player($ROLE, $PLAYER)?"); }
public void testCompletelyOpen() throws InvalidQueryException, IOException { load("bb-test.ltm"); List matches = new ArrayList(); Iterator it = topicmap.getAssociations().iterator(); while (it.hasNext()) { AssociationIF assoc = (AssociationIF) it.next(); Iterator it2 = assoc.getRoles().iterator(); while (it2.hasNext()) { AssociationRoleIF role = (AssociationRoleIF) it2.next(); addMatch(matches, "ASSOC", assoc, "ROLE", role); } } verifyQuery(matches, "association-role($ASSOC, $ROLE)?"); closeStore(); }
public void testSpecificAssoc() throws InvalidQueryException, IOException { load("bb-test.ltm"); List matches = new ArrayList(); Iterator it = topicmap.getAssociations().iterator(); AssociationIF assoc = (AssociationIF) it.next(); Iterator it2 = assoc.getRoles().iterator(); while (it2.hasNext()) { AssociationRoleIF role = (AssociationRoleIF) it2.next(); addMatch(matches, "ROLE", role); } verifyQuery(matches, "association-role(@" + assoc.getObjectId() + ", $ROLE)?"); closeStore(); }
private void clearTopicMap(TopicMapIF tm) throws Exception { // Remove all the objects from the topic map tm.clear(); Assert.assertTrue("Not all topics was deleted", tm.getTopics().isEmpty()); Assert.assertTrue("Not all associations was deleted", tm.getAssociations().isEmpty()); }
public void testMergeSelf() throws IOException { TopicMapIF tm1 = ImportExportUtils.getReader(TestFileUtils.getTestInputFile("query", "jill.xtm")).read(); TopicMapIF tm2 = ImportExportUtils.getReader(TestFileUtils.getTestInputFile("query", "jill.xtm")).read(); MergeUtils.mergeInto(tm1, tm2); assertEquals(tm1.getTopics().size(), tm2.getTopics().size()); assertEquals(tm1.getAssociations().size(), tm2.getAssociations().size()); }
public void testCompletelyOpen() throws InvalidQueryException, IOException { load("bb-test.ltm"); List matches = new ArrayList(); addScopesOf(matches, topicmap.getAssociations()); Iterator it = topicmap.getTopics().iterator(); while (it.hasNext()) { TopicIF topic = (TopicIF) it.next(); addScopesOf(matches, topic.getOccurrences()); addScopesOf(matches, topic.getTopicNames()); Iterator it2 = topic.getTopicNames().iterator(); while (it2.hasNext()) addScopesOf(matches, ((TopicNameIF) it2.next()).getVariants()); } verifyQuery(matches, "scope($SCOPED, $THEME)?"); }
@Test public void testEmptyTopicMap() throws IOException { TopicMapIF tm = readTopicMap("empty.xtm"); Assert.assertTrue("empty topic map not empty after import", tm.getTopics().size() == 0 && tm.getAssociations().size() == 0); Assert.assertTrue("topic map has no base address", tm.getStore().getBaseAddress() != null); }
@Test public void testTopicName() throws IOException { TopicMapIF tm = readTopicMap("basename.xtm"); Assert.assertTrue("wrong number of topics after import", tm.getTopics().size() == 6); Assert.assertTrue("spurious topic map constructs found", tm.getAssociations() .size() == 0); TopicIF topic = getTopicById(tm, "country"); verifySingleTopicName(topic, "Country"); }
public void testTopicAssociationRolePlayerDeletion() { TopicMapIF topicmap = makeTopicMap(); TopicMapBuilderIF builder = topicmap.getBuilder(); TopicIF morituri = builder.makeTopic(); TopicIF other = builder.makeTopic(); AssociationIF assoc = builder.makeAssociation(builder.makeTopic()); AssociationRoleIF role1 = builder.makeAssociationRole(assoc, builder.makeTopic(), morituri); AssociationRoleIF role2 = builder.makeAssociationRole(assoc, builder.makeTopic(), other); morituri.remove(); assertTrue("Topic still connected to topic map", morituri.getTopicMap() == null); assertTrue("Topic map has too many topics", topicmap.getTopics().size() == 4); assertTrue("Role still part of topic map", role1.getTopicMap() == null); assertTrue("other still has role", other.getRoles().size() == 0); assertTrue("Topic map lost association", topicmap.getAssociations().size() == 0); }
public void testAssociationRemoval() { TopicIF type = builder.makeTopic(); TopicIF role1 = builder.makeTopic(); TopicIF role2 = builder.makeTopic(); TopicIF player1 = builder.makeTopic(); TopicIF player2 = builder.makeTopic(); AssociationIF assoc = builder.makeAssociation(type); AssociationRoleIF role = builder.makeAssociationRole(assoc, role1, player1); role = builder.makeAssociationRole(assoc, role2, player2); assoc = builder.makeAssociation(type); role = builder.makeAssociationRole(assoc, role1, player1); role = builder.makeAssociationRole(assoc, role2, player2); DuplicateSuppressionUtils.removeDuplicates(topicmap); assertTrue("duplicate association was not removed", topicmap.getAssociations().size() == 1); }
public void testTopicAssociationDeletion() { TopicMapIF topicmap = makeTopicMap(); TopicMapBuilderIF builder = topicmap.getBuilder(); TopicIF morituri = builder.makeTopic(); TopicIF other = builder.makeTopic(); AssociationIF assoc = builder.makeAssociation(builder.makeTopic()); AssociationRoleIF role1 = builder.makeAssociationRole(assoc, builder.makeTopic(), morituri); AssociationRoleIF role2 = builder.makeAssociationRole(assoc, builder.makeTopic(), other); morituri.remove(); assertTrue("Topic still connected to topic map", morituri.getTopicMap() == null); assertTrue("Topic map has too many topics", topicmap.getTopics().size() == 4); assertTrue("Role 1 still connected to topic map", role1.getTopicMap() == null); assertTrue("Role 2 still connected to topic map", role2.getTopicMap() == null); assertTrue("Association still connected to topic map", assoc.getTopicMap() == null); assertTrue("Topic map still has association", topicmap.getAssociations().size() == 0); }