public static TopicNameIF makeTopicName(TopicIF ntype, TopicIF topicIF, String value, Collection<TopicIF> scope) { TopicMapBuilderIF builder = topicIF.getTopicMap().getBuilder(); TopicNameIF name = builder.makeTopicName(topicIF, ntype, value); Iterator<TopicIF> iter = scope.iterator(); while (iter.hasNext()) { TopicIF scopingTopic = iter.next(); name.addTheme(scopingTopic); } return name; }
public static TopicNameIF makeTopicName(TopicIF ntype, TopicIF topicIF, String value, Collection<TopicIF> scope) { TopicMapBuilderIF builder = topicIF.getTopicMap().getBuilder(); TopicNameIF name = builder.makeTopicName(topicIF, ntype, value); Iterator<TopicIF> iter = scope.iterator(); while (iter.hasNext()) { TopicIF scopingTopic = iter.next(); name.addTheme(scopingTopic); } return name; }
name.addTheme((TopicIF) itT.next());
public void testBNSDouble1() { TopicIF theme = builder.makeTopic(); TopicNameIF bn1 = builder.makeTopicName(topic, "Name1"); TopicNameIF bn2 = builder.makeTopicName(topic, "Name2"); bn2.addTheme(theme); Set scope = new HashSet(); scope.add(theme); StringifierIF sf = TopicStringifiers.getTopicNameStringifier(scope); assertTrue("Stringifying topic gave wrong name", sf.toString(topic).equals("Name2")); }
@Override public void run() { TopicNameIF bn = getTopicName(); TopicIF theme = builder.makeTopic(); this.data.put("scope", theme); bn.addTheme(theme); this.objectId = bn.getObjectId(); this.value = theme.getObjectId(); } });
public void testTopicNameAndVariantNameRemovalWithScope() { TopicIF theme1 = builder.makeTopic(); TopicIF theme2 = builder.makeTopic(); TopicIF topic = builder.makeTopic(); TopicNameIF bn = builder.makeTopicName(topic, "test"); bn.addTheme(theme1); bn.addTheme(theme2); VariantNameIF vn = builder.makeVariantName(bn, "duplicate"); TopicNameIF bn2 = builder.makeTopicName(topic, "test"); bn2.addTheme(theme1); bn2.addTheme(theme2); vn = builder.makeVariantName(bn, "duplicate"); DuplicateSuppressionUtils.removeDuplicates(topic); assertTrue("duplicate base names were not removed", topic.getTopicNames().size() == 1); bn = (TopicNameIF) topic.getTopicNames().iterator().next(); assertTrue("duplicate variant names were not removed", bn.getVariants().size() == 1); }
public void testSeveralTopicNames() { TopicIF dummy1 = builder1.makeTopic(); TopicIF dummy2 = builder1.makeTopic(); TopicIF t1 = builder1.makeTopic(); TopicNameIF bn1 = builder1.makeTopicName(t1, "Ontopia"); bn1.addTheme(t1); TopicNameIF bn2 = builder1.makeTopicName(t1, "Ontopia"); bn2.addTheme(dummy1); TopicNameIF bn3 = builder1.makeTopicName(t1, "Ontopia"); bn3.addTheme(dummy2); TopicNameIF bn4 = builder1.makeTopicName(t1, "Ontopia"); bn4.addTheme(dummy1); bn4.addTheme(dummy2); TopicNameIF bn5 = builder1.makeTopicName(t1, "Ontopia"); TopicIF t2 = builder2.makeTopic(); builder2.makeTopicName(t2, "Ontopia"); assertTrue("claims topics should merge when they have same BN in unconstrained scope", !MergeUtils.shouldMerge(t1, t2)); }
public void testTopicNameRemovalWithScope() { TopicIF theme1 = builder.makeTopic(); TopicIF theme2 = builder.makeTopic(); TopicIF topic = builder.makeTopic(); TopicNameIF bn = builder.makeTopicName(topic, "test"); bn.addTheme(theme1); bn.addTheme(theme2); VariantNameIF vn = builder.makeVariantName(bn, "not duplicate"); TopicNameIF bn2 = builder.makeTopicName(topic, "test"); bn2.addTheme(theme1); bn2.addTheme(theme2); vn = builder.makeVariantName(bn, "not duplicate, either"); DuplicateSuppressionUtils.removeDuplicates(topic); assertTrue("duplicate base names were not removed", topic.getTopicNames().size() == 1); bn = (TopicNameIF) topic.getTopicNames().iterator().next(); assertTrue("variant names were not merged", bn.getVariants().size() == 2); }
/** * PUBLIC: Merges the source topic name into the target topic in * another topic map. Makes no attempt to verify that the source * topic represents the same subject as the target topic. * @return The new topic name in the target topic map. * @since 5.1.3 */ public static TopicNameIF mergeInto(TopicIF target, TopicNameIF source) { TopicMapIF tm = target.getTopicMap(); TopicMapBuilderIF builder = tm.getBuilder(); TopicIF type = findTopic(tm, source.getType()); TopicNameIF newtn = builder.makeTopicName(target, type, source.getValue()); for (TopicIF theme : source.getScope()) newtn.addTheme(findTopic(tm, theme)); return newtn; }
public void testBNSDouble2() { TopicIF theme = builder.makeTopic(); TopicNameIF bn1 = builder.makeTopicName(topic, "Name1"); TopicNameIF bn2 = builder.makeTopicName(topic, "Name2"); bn2.addTheme(theme); StringifierIF sf = TopicStringifiers.getTopicNameStringifier(empty); assertTrue("Stringifying topic gave wrong name", sf.toString(topic).equals("Name1")); }
public void testSSComplex() { TopicIF theme = builder.makeTopic(); TopicNameIF bn1 = builder.makeTopicName(topic, "Name1"); TopicNameIF bn2 = builder.makeTopicName(topic, "Name2"); bn2.addTheme(theme); StringifierIF sf = TopicStringifiers.getSortNameStringifier(); assertTrue("Stringifying topic gave wrong name", sf.toString(topic).equals("Name1")); }
public void testDSComplex() { TopicIF theme = builder.makeTopic(); TopicNameIF bn1 = builder.makeTopicName(topic, "Name1"); TopicNameIF bn2 = builder.makeTopicName(topic, "Name2"); bn2.addTheme(theme); StringifierIF sf = TopicStringifiers.getDefaultStringifier(); assertTrue("Stringifying topic gave wrong name", sf.toString(topic).equals("Name1")); }
public void testTopicNameBound() throws InvalidQueryException, IOException { makeEmpty(); TopicIF theme = builder.makeTopic(); TopicIF topic = builder.makeTopic(); TopicNameIF thing = builder.makeTopicName(topic, "mybasename"); thing.addTheme(theme); List matches = new ArrayList(); addMatch(matches, "THEME", theme); verifyQuery(matches, "scope(@" + thing.getObjectId() + ", $THEME)?"); }
public void testTopicNameBothUnbound() throws InvalidQueryException, IOException { makeEmpty(); TopicIF theme = builder.makeTopic(); TopicIF topic = builder.makeTopic(); TopicNameIF thing = builder.makeTopicName(topic, "mybasename"); thing.addTheme(theme); List matches = new ArrayList(); addMatch(matches, "THING", thing, "THEME", theme); // NOTE: using topic-name predicate here to avoid type cross product verifyQuery(matches, "topic-name(@" + topic.getObjectId() + ", $THING), scope($THING, $THEME)?"); }
public void testTopicNameUnbound() throws InvalidQueryException, IOException { makeEmpty(); TopicIF theme = builder.makeTopic(); TopicIF topic = builder.makeTopic(); TopicNameIF thing = builder.makeTopicName(topic, "mybasename"); thing.addTheme(theme); List matches = new ArrayList(); addMatch(matches, "THING", thing); // NOTE: using topic-name predicate here to avoid type cross product verifyQuery(matches, "topic-name(@" + topic.getObjectId() + ", $THING), scope($THING, @" + theme.getObjectId() + ")?"); }
public void testTopicNameBothBound() throws InvalidQueryException, IOException { makeEmpty(); TopicIF theme = builder.makeTopic(); TopicIF topic = builder.makeTopic(); TopicNameIF thing = builder.makeTopicName(topic, "mybasename"); thing.addTheme(theme); List matches = new ArrayList(); addMatch(matches); verifyQuery(matches, "scope(@" + thing.getObjectId() + ", @" + theme.getObjectId() + ")?"); }
public void testMergeTopicNameScopeUse() { try { TopicIF t1 = builder1.makeTopic(); TopicIF t2 = builder1.makeTopic(); TopicNameIF bn = builder1.makeTopicName(t1, ""); bn.addTheme(t2); MergeUtils.mergeInto(t1, t2); assertTrue("base name scope corrupted", bn.getScope().size() == 1); assertTrue("base name theme replacement not done correctly", bn.getScope().contains(t1)); } catch (ConstraintViolationException e) { fail("merge of topics unaccountably failed" + e.getMessage()); } }
@Before public void setUp() { topicmap = new InMemoryTopicMapStore().getTopicMap(); TopicMapBuilderIF builder = topicmap.getBuilder(); topic = builder.makeTopic(); TopicIF type = builder.makeTopic(); scope = builder.makeTopic(); untyped = builder.makeTopicName(topic, "Untyped name"); typed = builder.makeTopicName(topic, type, "Typed"); untyped_scoped = builder.makeTopicName(topic, "Untyped, scoped"); typed_scoped = builder.makeTopicName(topic, type, "Typed, scoped"); untyped_scoped.addTheme(scope); typed_scoped.addTheme(scope); }
public void testTopicNameScopeCopy() { // used to have a bug on this, hence the test TopicIF tt1 = builder1.makeTopic(); builder1.makeTopicName(tt1, "basename1"); TopicIF tt2 = builder2.makeTopic(); TopicIF t2 = builder2.makeTopic(); t2.addItemIdentifier(makeLocator("http://www.ontopia.net")); TopicNameIF bn1 = builder2.makeTopicName(t2, "basename2"); bn1.addTheme(tt2); int before = topicmap1.getTopics().size(); MergeUtils.mergeInto(topicmap1, topicmap2); assertTrue("incorrect number of topics in merged topic map", topicmap1.getTopics().size() == (before + 2)); t2 = (TopicIF) topicmap1.getObjectByItemIdentifier(makeLocator("http://www.ontopia.net")); bn1 = (TopicNameIF) t2.getTopicNames().iterator().next(); assertTrue("merged topic lost base name", bn1 != null); assertTrue("merged base name lost scope", bn1.getScope().size() == 1); }
theme.addSubjectIdentifier(makeLocator("http://www.ontopia.net")); builder2.makeTopicName(theme, "The theme"); bn.addTheme(theme);