protected void writeParameters(VariantNameIF variant, ContentHandler dh) throws SAXException { Collection params = variant.getScope(); if (!params.isEmpty()) { dh.startElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "parameters", EMPTY_ATTR_LIST); Iterator it = params.iterator(); while (it.hasNext()) writeTopicRef((TopicIF) it.next(), dh); dh.endElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "parameters"); } }
@Override public int compare(VariantNameIF vn1, VariantNameIF vn2) { if (Objects.equals(vn1, vn2)) return 0; int retVal = scopeComparator.compare(filterCollection(vn1.getScope()), filterCollection(vn2.getScope())); if (retVal == 0) retVal = lazyStringCompare(vn1.getValue(), vn2.getValue()); return retVal; }
@Override protected void writeVariants(Collection variants, ContentHandler dh) throws SAXException { Iterator iter = variants.iterator(); while (iter.hasNext()) { VariantNameIF var = (VariantNameIF)iter.next(); dh.startElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "variant", EMPTY_ATTR_LIST); // write parameters if (var.getScope().size() > 0) writeParameters(var, dh); else { // FIXME : XTM violation! } // write variantName writeVariantName(var, dh); dh.endElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "variant"); } }
/** * Get the first VariantNameIF that is scoped by a single topic, having the * given subject indicator. * @param variants The variants to search through. * @param si The subject indicator to search for. * @return The first matching VariantNameIF, or null if none is found. */ private VariantNameIF firstNameWithScopingPSI(Collection<VariantNameIF> variants, LocatorIF si) { VariantNameIF firstName = null; Iterator<VariantNameIF> it = variants.iterator(); while (firstName == null && it.hasNext()) { VariantNameIF currentVariant = it.next(); Collection<TopicIF> scope = filterCollection(currentVariant.getScope()); if (scope.size() == 1) { TopicIF scopingTopic = scope.iterator().next(); Collection<LocatorIF> scopingPSIs = scopingTopic.getSubjectIdentifiers(); if (scopingPSIs.contains(si)) firstName = currentVariant; } } return firstName; }
/** * Accepts or rejects a VariantNameIF * @param variantName to be accepted/rejected. * @return true iff variantName is accepted by the filter and its scope is * also accepted by the filter. */ public boolean ok(VariantNameIF variantName) { return filter.ok(variantName) && filter.ok(variantName.getScope()); }
@Override public int compare(Object o1, Object o2) { VariantNameIF vn1 = (VariantNameIF) o1; VariantNameIF vn2 = (VariantNameIF) o2; int cmp = compareString(vn1.getValue(), vn2.getValue()); if (cmp == 0) cmp = compareLocator(vn1.getLocator(), vn2.getLocator()); if (cmp == 0) cmp = compareTopicSet(vn1.getScope(), vn2.getScope()); return cmp; }
while (it.hasNext()) { VariantNameIF candidate = it.next(); Collection<TopicIF> scope = candidate.getScope(); int themes; if (scope.contains(sort))
while (it.hasNext()) { VariantNameIF svn = it.next(); Collection<TopicIF> tscope = translateScope(target, svn.getScope()); String key = KeyGenerator.makeScopeKey(tscope) + KeyGenerator.makeDataKey(svn);
@Override public void run(MasterTest mt) { VariantNameIF vn = (VariantNameIF)topicmap.getObjectById(mt.objectId); assertTrue("Variant name theme is set", vn.getScope().isEmpty()); } });
@Override public int compare(VariantNameIF vn1, VariantNameIF vn2) { if (vn1 == vn2) return 0; // Compare variant name values int cval1 = compareObjects(vn1.getValue(), vn2.getValue()); if (cval1 != 0) return cval1; // Compare variant name locators int cval2 = compareObjects(vn1.getLocator(), vn2.getLocator(), LocatorComparator.getInstance()); if (cval2 != 0) return cval2; // Compare scope return compareCollections(vn1.getScope(), vn2.getScope(), TopicComparator.getInstance()); } }
while (it.hasNext()) { VariantNameIF candidate = (VariantNameIF) it.next(); Collection scope = candidate.getScope(); int themes; if (scope.contains(vntheme)) {
@Override public void run(MasterTest mt) { VariantNameIF vn = (VariantNameIF)topicmap.getObjectById(mt.objectId); TopicIF theme = (TopicIF)topicmap.getObjectById(mt.value); assertTrue("Variant name theme is not set", vn.getScope().contains(theme)); } });
SnapshotVariantName(VariantNameIF original, int snapshotType, Map<TMObjectIF, SnapshotTMObject> processed) { this.snapshotType = snapshotType; switch (snapshotType) { case SNAPSHOT_REFERENCE: this.objectId = original.getObjectId(); break; case SNAPSHOT_COMPLETE: this.objectId = original.getObjectId(); this.srclocs = new ArrayList<LocatorIF>(original.getItemIdentifiers()); this.basename = SnapshotTopicName.makeSnapshot(original.getTopicName(), SnapshotTopic.SNAPSHOT_REFERENCE, processed); this.topic = SnapshotTopic.makeSnapshot(original.getTopic(), SnapshotTopic.SNAPSHOT_REFERENCE, processed); this.datatype = original.getDataType(); this.value = original.getValue(); this.scope = new ArrayList<TopicIF>(); Iterator<TopicIF> siter = original.getScope().iterator(); while (siter.hasNext()) { this.scope.add(SnapshotTopic.makeSnapshot(siter.next(), snapshotType, processed)); } this.reifier = SnapshotTopic.makeSnapshot(original.getReifier(), SnapshotTopic.SNAPSHOT_REFERENCE, processed); break; default: throw new OntopiaRuntimeException("Unknown snapshot type: " + snapshotType); } }
while (it2.hasNext()) { VariantNameIF vn = (VariantNameIF) it2.next(); findPrefixFor(vn.getScope());
public void testMergeVariantNameScopeUse() { try { TopicIF t1 = builder1.makeTopic(); TopicIF t2 = builder1.makeTopic(); TopicNameIF bn = builder1.makeTopicName(t1, ""); VariantNameIF vn = builder1.makeVariantName(bn, ""); vn.addTheme(t2); MergeUtils.mergeInto(t1, t2); assertTrue("variant name scope corrupted", vn.getScope().size() == 1); assertTrue("variant name theme replacement not done correctly", vn.getScope().contains(t1)); } catch (ConstraintViolationException e) { fail("merge of topics unaccountably failed" + e.getMessage()); } }
@Test public void testVariants() throws IOException { TopicMapIF tm = readTopicMap("variants.xtm"); Assert.assertTrue("wrong number of topics after import", tm.getTopics().size() == 3); Assert.assertTrue("spurious topic map constructs found", tm.getAssociations() .size() == 0); TopicIF country = getTopicById(tm, "country"); TopicIF norwegian = getTopicById(tm, "norwegian"); Assert.assertTrue("topic has spurious children", country.getTypes().size() == 0 && country.getRoles().size() == 0 && country.getOccurrences().size() == 0); Assert.assertTrue("topic has wrong number of base names", country.getTopicNames() .size() == 1); TopicNameIF basename = (TopicNameIF) country.getTopicNames().iterator() .next(); Assert.assertTrue("wrong basename value: '" + basename.getValue() + "'", basename .getValue().equals("Country")); Assert.assertTrue("wrong number of variant children", basename.getVariants() .size() == 1); VariantNameIF variant = (VariantNameIF) basename.getVariants().iterator() .next(); Assert.assertTrue("wrong variant value: '" + variant.getValue() + "'", variant .getValue().equals("Land")); Assert.assertTrue("wrong scope of variant", variant.getScope().size() == 1 && variant.getScope().iterator().next().equals(norwegian)); }
private void write(VariantNameIF variant, int number) { AttributesImpl attributes = reifier(variant); attributes.addAttribute("", "", AT_NUMBER, null, "" + number); startElement(EL_VARIANT, attributes); attributes.clear(); if (Objects.equals(variant.getDataType(), DataTypes.TYPE_URI)) { LocatorIF locator = variant.getLocator(); if (locator != null) write(normaliseLocatorReference(locator.getAddress())); } else { String value = variant.getValue(); if (value != null) write(value); } write(variant.getDataType(), "datatype"); write(variant.getScope()); writeLocators(variant.getItemIdentifiers(), EL_ITEMIDENTIFIERS); endElement(EL_VARIANT); }
@Override public void run(MasterTest mt) { VariantNameIF vn = (VariantNameIF)topicmap.getObjectById(mt.objectId); assertTrue("Added variant name not found", vn != null); if (testInitialProperties) { assertTrue("Source locators is set", vn.getItemIdentifiers().isEmpty()); assertTrue("Scope is set", vn.getScope().isEmpty()); assertTrue("Value is set", vn.getValue() == null); assertTrue("Locator is set", vn.getLocator() == null); } } });
value = variant.getLocator().getAddress(); value = variant.getScope().size() + value; } else { throw new OntopiaRuntimeException("NameComparator Error: This comparator only compares " +