@Override public int compare(TopicNameIF bn1, TopicNameIF bn2) { if (Objects.equals(bn1, bn2)) return 0; int retVal = scopeComparator.compare(filterCollection(bn1.getScope()), filterCollection(bn2.getScope())); if (retVal == 0) retVal = lazyStringCompare(bn1.getValue(), bn2.getValue()); return retVal; }
public static List<TopicNameIF> findTopicNames(TopicIF nType, TopicIF topicIF, Collection<TopicIF> scope) { List<TopicNameIF> result = new ArrayList<TopicNameIF>(); Iterator<TopicNameIF> it = topicIF.getTopicNames().iterator(); while (it.hasNext()) { TopicNameIF nameIF = it.next(); if (Objects.equals(nameIF.getType(), nType) && CollectionUtils.equalsUnorderedSet(nameIF.getScope(), scope)) result.add(nameIF); } return result; }
/** * Returns all topics with no name in the unconstrained scope */ public Collection getNoNameUnconstrained() { Collection retur = new ArrayList(); Iterator it = tm.getTopics().iterator(); while (it.hasNext()) { TopicIF topic = (TopicIF) it.next(); boolean noname = true; Iterator it2 = topic.getTopicNames().iterator(); while (noname && it2.hasNext()) { TopicNameIF bn = (TopicNameIF) it2.next(); noname = !bn.getScope().isEmpty(); } if (noname) retur.add(topic); } return retur; }
public static List<TopicNameIF> findTopicNames(TopicIF nType, TopicIF topicIF, String value, Collection<TopicIF> scope) { List<TopicNameIF> result = new ArrayList<TopicNameIF>(); Iterator<TopicNameIF> it = topicIF.getTopicNames().iterator(); while (it.hasNext()) { TopicNameIF nameIF = it.next(); if (Objects.equals(nameIF.getValue(), value) && Objects.equals(nameIF.getType(), nType) && CollectionUtils.equalsUnorderedSet(nameIF.getScope(), scope)) result.add(nameIF); } return result; }
/** * INTERNAL: Returns the topics that have a basename with the given * string value in the given scope.<p> * * This method is used to look up topics in the socalled topic name * space. Note that whether a single topic is returned depends on * whether the topic map have been completely processed or not. */ public Collection<TopicIF> getTopics(String basename_string, Collection<TopicIF> scope) { HashSet<TopicIF> topics = new HashSet<TopicIF>(); Iterator<TopicNameIF> it = nameix.getTopicNames(basename_string).iterator(); while (it.hasNext()) { TopicNameIF bn = it.next(); if (bn.getScope().equals(scope)) topics.add(bn.getTopic()); } return topics; }
public static List<TopicNameIF> findTopicNames(TopicIF nType, TopicIF topicIF, Collection<TopicIF> scope) { List<TopicNameIF> result = new ArrayList<TopicNameIF>(); Iterator<TopicNameIF> it = topicIF.getTopicNames().iterator(); while (it.hasNext()) { TopicNameIF nameIF = it.next(); if (ObjectUtils.equals(nameIF.getType(), nType) && CollectionUtils.equalsUnorderedSet(nameIF.getScope(), scope)) result.add(nameIF); } return result; }
/** * Accepts or rejects a TopicNameIF * @param baseName to be accepted/rejected. * @return true iff baseName is accepted by the filter and its scope is also * accepted by the filter. */ public boolean ok(TopicNameIF baseName) { return filter.ok(baseName) && filter.ok(baseName.getScope()); }
@Override public int compare(Object o1, Object o2) { TopicNameIF bn1 = (TopicNameIF) o1; TopicNameIF bn2 = (TopicNameIF) o2; int cmp = compareString(bn1.getValue(), bn2.getValue()); // FIXME: Compare by type here when we can! if (cmp == 0) cmp = compareTopicSet(bn1.getScope(), bn2.getScope()); return cmp; }
public static List<TopicNameIF> findTopicNames(TopicIF nType, TopicIF topicIF, String value, Collection<TopicIF> scope) { List<TopicNameIF> result = new ArrayList<TopicNameIF>(); Iterator<TopicNameIF> it = topicIF.getTopicNames().iterator(); while (it.hasNext()) { TopicNameIF nameIF = it.next(); if (ObjectUtils.equals(nameIF.getValue(), value) && ObjectUtils.equals(nameIF.getType(), nType) && CollectionUtils.equalsUnorderedSet(nameIF.getScope(), scope)) result.add(nameIF); } return result; }
protected void _removeTheme(TopicIF theme, boolean validate) { if (theme == null) throw new NullPointerException("null is not a valid argument."); CrossTopicMapException.check(theme, this); // Notify listeners fireEvent(VariantNameIF.EVENT_REMOVE_THEME, null, theme); // Remove theme from scope scope = topicmap.setpool.remove(scope, theme, true); // complain if theme already defined on parent if (validate && parent != null && ((TopicNameIF)parent).getScope().contains(theme)) { throw new ConstraintViolationException("Can't remove theme from variant when theme is declared on topic name value."); } }
protected void _removeTheme(TopicIF theme, boolean validate) { if (theme == null) throw new NullPointerException("null is not a valid argument."); CrossTopicMapException.check(theme, this); // Notify listeners fireEvent(VariantNameIF.EVENT_REMOVE_THEME, null, theme); // Notify transaction valueRemoved(LF_scope, theme, true); // complain if theme already defined on parent if (validate) { TopicNameIF parent = getTopicName(); if (parent != null && parent.getScope().contains(theme)) throw new ConstraintViolationException("Can't remove theme from variant when theme is declared on topic name value."); } }
@Override public void run(MasterTest mt) { TopicNameIF bn = (TopicNameIF)topicmap.getObjectById(mt.objectId); assertTrue("Base name theme is set", bn.getScope().isEmpty()); } });
@Override public int compare(TopicNameIF bn1, TopicNameIF bn2) { if (Objects.equals(bn1, bn2)) return 0; // Compare basename values int cval1 = compareObjects(bn1.getValue(), bn2.getValue()); if (cval1 != 0) return cval1; // Compare scope int cval2 = compareCollections(bn1.getScope(), bn2.getScope(), TopicComparator.getInstance()); if (cval2 != 0) return cval2; // Compare variant names return compareCollections(bn1.getVariants(), bn2.getVariants(), VariantNameComparator.getInstance()); } }
public void testScopeDynamic() throws InvalidQueryException, IOException { load("bb-ontologi.ltm"); TopicIF topic = getTopicById("bbtype"); Iterator it = topic.getTopicNames().iterator(); TopicNameIF name = (TopicNameIF) it.next(); if (name.getScope().isEmpty()) // need the one with scope name = (TopicNameIF) it.next(); update("delete scope($N, english) from topic-name(bbtype, $N), scope($N, english)"); assertTrue("name retains scope after delete", name.getScope().isEmpty()); }
@Override public void run(MasterTest mt) { TopicNameIF bn = (TopicNameIF)topicmap.getObjectById(mt.objectId); TopicIF theme = (TopicIF)topicmap.getObjectById(mt.value); assertTrue("Base name theme is not set", bn.getScope().contains(theme)); } });
private void write(TopicNameIF basename, int number) { AttributesImpl attributes = reifier(basename); attributes.addAttribute("", "", AT_NUMBER, null, "" + number); startElement(EL_NAME, attributes); attributes.clear(); write(basename.getValue()); writeType(basename); write(basename.getScope()); Object[] variants = basename.getVariants().toArray(); Arrays.sort(variants, variantComparator); for (int ix = 0; ix < variants.length; ix++) write((VariantNameIF) variants[ix], ix + 1); writeLocators(basename.getItemIdentifiers(), EL_ITEMIDENTIFIERS); endElement(EL_NAME); }
private void verifySingleTopicName(TopicIF topic, String name) { Assert.assertTrue("topic has spurious children", topic.getTypes().size() == 0 && topic.getRoles().size() == 0 && topic.getOccurrences().size() == 0); Assert.assertTrue("topic has wrong number of base names", topic.getTopicNames() .size() == 1); TopicNameIF basename = (TopicNameIF) topic.getTopicNames().iterator() .next(); Assert.assertTrue("wrong basename value: '" + basename.getValue() + "'", basename .getValue().equals(name)); Assert.assertTrue("basename has spurious children", basename.getVariants().size() == 0); Assert.assertTrue("basename has spurious themes", basename.getScope().size() == 0); }
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()); } }
/** * 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; }
@Override public void run(MasterTest mt) { TopicNameIF bn = (TopicNameIF)topicmap.getObjectById(mt.objectId); assertTrue("Added base name not found", bn != null); if (testInitialProperties) { assertTrue("Source locators is set", bn.getItemIdentifiers().isEmpty()); assertTrue("Scope is set", bn.getScope().isEmpty()); assertTrue("Type is set", bn.getType() == null); assertTrue("Value is set", "".equals(bn.getValue())); assertTrue("Variants is set", bn.getVariants().isEmpty()); } } });