|
From: <lh...@us...> - 2008-11-27 15:55:51
|
Revision: 240
http://tinytim.svn.sourceforge.net/tinytim/?rev=240&view=rev
Author: lheuer
Date: 2008-11-27 15:55:32 +0000 (Thu, 27 Nov 2008)
Log Message:
-----------
A few examples
Added Paths:
-----------
tinytim-examples/trunk/src/main/java/org/tinytim/examples/tinytim/AbstractDuplicateRemovalExample.java
tinytim-examples/trunk/src/main/java/org/tinytim/examples/tinytim/RemoveDuplicateNames.java
tinytim-examples/trunk/src/main/java/org/tinytim/examples/tinytim/RemoveDuplicateOccurrences.java
tinytim-examples/trunk/src/main/java/org/tinytim/examples/tinytim/mio/
Added: tinytim-examples/trunk/src/main/java/org/tinytim/examples/tinytim/AbstractDuplicateRemovalExample.java
===================================================================
--- tinytim-examples/trunk/src/main/java/org/tinytim/examples/tinytim/AbstractDuplicateRemovalExample.java (rev 0)
+++ tinytim-examples/trunk/src/main/java/org/tinytim/examples/tinytim/AbstractDuplicateRemovalExample.java 2008-11-27 15:55:32 UTC (rev 240)
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2008 Lars Heuer (heuer[at]semagia.com). All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.tinytim.examples.tinytim;
+
+import org.tmapi.core.Locator;
+import org.tmapi.core.TMAPIException;
+import org.tmapi.core.Topic;
+import org.tmapi.core.TopicMap;
+import org.tmapi.core.TopicMapSystem;
+import org.tmapi.core.TopicMapSystemFactory;
+
+/**
+ * Base class for the duplicate removal examples.
+ *
+ * Sets up the topic map system and provides some utility methods.
+ *
+ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
+ * @version $Rev:$ - $Date:$
+ */
+abstract class AbstractDuplicateRemovalExample {
+
+ protected TopicMapSystem _system;
+ protected TopicMap _topicMap;
+ protected Locator _tmIRI;
+
+ /**
+ * Creates a topic with the item identifier "a-topic"
+ */
+ protected Topic createTopic() throws TMAPIException {
+ final Locator iid = resolve("a-topic");
+ System.out.println("Creating a topic with the item identifier '" + iid.getReference() + "'");
+ Topic topic = _topicMap.createTopicByItemIdentifier(iid);
+ System.out.println("Created the topic");
+ return topic;
+ }
+
+ /**
+ * Returns a locator resolved against the base locator
+ */
+ protected Locator resolve(String localId) {
+ return _tmIRI.resolve("#" + localId);
+ }
+
+ protected Topic createTopic(String localId) {
+ return _topicMap.createTopicByItemIdentifier(resolve(localId));
+ }
+
+ protected Locator createLocator(String reference) {
+ return _tmIRI.resolve(reference);
+ }
+
+ protected void runExample() throws TMAPIException {
+ _system = TopicMapSystemFactory.newInstance().newTopicMapSystem();
+ _tmIRI = _system.createLocator("http://tinytim.sourceforge/example/remove-duplicates");
+ _topicMap = _system.createTopicMap(_tmIRI);
+ }
+}
Property changes on: tinytim-examples/trunk/src/main/java/org/tinytim/examples/tinytim/AbstractDuplicateRemovalExample.java
___________________________________________________________________
Added: svn:keywords
+ Rev Date Id
Added: svn:eol-style
+ native
Added: tinytim-examples/trunk/src/main/java/org/tinytim/examples/tinytim/RemoveDuplicateNames.java
===================================================================
--- tinytim-examples/trunk/src/main/java/org/tinytim/examples/tinytim/RemoveDuplicateNames.java (rev 0)
+++ tinytim-examples/trunk/src/main/java/org/tinytim/examples/tinytim/RemoveDuplicateNames.java 2008-11-27 15:55:32 UTC (rev 240)
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2008 Lars Heuer (heuer[at]semagia.com). All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.tinytim.examples.tinytim;
+
+import org.tinytim.utils.DuplicateRemovalUtils;
+
+import org.tmapi.core.Name;
+import org.tmapi.core.TMAPIException;
+import org.tmapi.core.Topic;
+
+/**
+ * This example shows how to use the {@DuplicateRemovalUtils} and the effects of the
+ * DuplicateRemovalUtils on topic names.
+ *
+ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
+ * @version $Rev:$ - $Date:$
+ */
+public class RemoveDuplicateNames extends AbstractDuplicateRemovalExample {
+
+ public static void main(String[] args) {
+ RemoveDuplicateNames example = new RemoveDuplicateNames();
+ try {
+ example.runExample();
+ }
+ catch (TMAPIException ex) {
+ ex.printStackTrace();
+ }
+ }
+
+ public void runExample() throws TMAPIException {
+ super.runExample();
+ Topic topic = createTopic();
+ final String value = "tinyTiM";
+ System.out.println("Creating a name: '" + value + "'");
+ topic.createName(value);
+ System.out.println("Created the name.");
+ System.out.println("Creating another name with the same value: '" + value + "'");
+ topic.createName(value);
+ System.out.println("Created the name.");
+ System.out.println("The topic has " + topic.getNames().size() + " names:");
+ for (Name name: topic.getNames()) {
+ System.out.println("- " + name.getValue());
+ }
+ System.out.println("=> The topic has two names with the value '" + value + "' (duplicates)");
+ System.out.println("Invoking " + DuplicateRemovalUtils.class.getName() + ".removeDuplicates(topic)");
+ DuplicateRemovalUtils.removeDuplicates(topic);
+ System.out.println("The topic has " + topic.getNames().size() + " name:");
+ for (Name name: topic.getNames()) {
+ System.out.println("- " + name.getValue());
+ }
+ System.out.println("=> The topic has no duplicate names");
+ }
+
+}
Property changes on: tinytim-examples/trunk/src/main/java/org/tinytim/examples/tinytim/RemoveDuplicateNames.java
___________________________________________________________________
Added: svn:keywords
+ Rev Date Id
Added: svn:eol-style
+ native
Added: tinytim-examples/trunk/src/main/java/org/tinytim/examples/tinytim/RemoveDuplicateOccurrences.java
===================================================================
--- tinytim-examples/trunk/src/main/java/org/tinytim/examples/tinytim/RemoveDuplicateOccurrences.java (rev 0)
+++ tinytim-examples/trunk/src/main/java/org/tinytim/examples/tinytim/RemoveDuplicateOccurrences.java 2008-11-27 15:55:32 UTC (rev 240)
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2008 Lars Heuer (heuer[at]semagia.com). All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.tinytim.examples.tinytim;
+
+import org.tinytim.utils.DuplicateRemovalUtils;
+
+import org.tmapi.core.Occurrence;
+import org.tmapi.core.TMAPIException;
+import org.tmapi.core.Topic;
+
+/**
+ * This example shows how to use the {@DuplicateRemovalUtils} and the effects of the
+ * DuplicateRemovalUtils on occurrences.
+ *
+ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
+ * @version $Rev:$ - $Date:$
+ */
+public class RemoveDuplicateOccurrences extends AbstractDuplicateRemovalExample {
+
+ /**
+ *
+ *
+ * @param args
+ */
+ public static void main(String[] args) {
+ RemoveDuplicateOccurrences example = new RemoveDuplicateOccurrences();
+ try {
+ example.runExample();
+ }
+ catch (TMAPIException ex) {
+ ex.printStackTrace();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.tinytim.examples.tinytim.AbstractDuplicateRemovalExample#runExample()
+ */
+ public void runExample() throws TMAPIException {
+ super.runExample();
+ Topic topic = createTopic();
+ final String website = "website";
+ final String value = "http://tinytim.sourceforge.net/";
+ System.out.println("Creating an occurrence with the type: '" + website + "' and the URI value '" + value + "'");
+ createWebsite(topic, value);
+ System.out.println("Created the occurrence.");
+ System.out.println("Creating another occurrence with the type and value: '" + website + "' and the URI value '" + value + "'");
+ createWebsite(topic, value);
+ System.out.println("Created the occurrence.");
+ System.out.println("The topic has " + topic.getOccurrences().size() + " occurrences:");
+ for (Occurrence occ: topic.getOccurrences()) {
+ System.out.println("* " + occ.getValue());
+ }
+ System.out.println("=> The topic has two occs with the value '" + value + "' (duplicates)");
+ System.out.println("Invoking " + DuplicateRemovalUtils.class.getName() + ".removeDuplicates(topic)");
+ DuplicateRemovalUtils.removeDuplicates(topic);
+ System.out.println("The topic has " + topic.getOccurrences().size() + " occurrence:");
+ for (Occurrence occ: topic.getOccurrences()) {
+ System.out.println("* " + occ.getValue());
+ }
+ System.out.println("=> The topic has no duplicate occurrences");
+ }
+
+ /**
+ * Creates an occurrence of type "website"
+ */
+ private void createWebsite(Topic topic, String value) {
+ topic.createOccurrence(createTopic("website"), createLocator(value));
+ }
+
+}
Property changes on: tinytim-examples/trunk/src/main/java/org/tinytim/examples/tinytim/RemoveDuplicateOccurrences.java
___________________________________________________________________
Added: svn:keywords
+ Rev Date Id
Added: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|