You can subscribe to this list here.
2005 |
Jan
|
Feb
|
Mar
(85) |
Apr
|
May
|
Jun
|
Jul
(21) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
---|---|---|---|---|---|---|---|---|---|---|---|---|
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(4) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Tobias R. <tob...@us...> - 2007-07-09 22:15:52
|
Update of /cvsroot/tmapi-utils/tmapi-utils In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv17275 Modified Files: CHANGES.txt Log Message: Index: CHANGES.txt =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/CHANGES.txt,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** CHANGES.txt 9 Jul 2007 21:30:45 -0000 1.2 --- CHANGES.txt 9 Jul 2007 22:15:54 -0000 1.3 *************** *** 5,7 **** 2007-07-09 Tobias Redmann: - added setEncoding for XTMSerializer to save XTM in any encoding, default is still ISO-8859-1 ! --- 5,7 ---- 2007-07-09 Tobias Redmann: - added setEncoding for XTMSerializer to save XTM in any encoding, default is still ISO-8859-1 ! - added setEncoding for XTMParser |
From: Tobias R. <tob...@us...> - 2007-07-09 22:14:39
|
Update of /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/impexp/xtm In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv16455 Modified Files: XTMParser.java Log Message: Added setEncoding to parse XTM of any kind Index: XTMParser.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/impexp/xtm/XTMParser.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** XTMParser.java 3 Mar 2005 17:33:32 -0000 1.4 --- XTMParser.java 9 Jul 2007 22:14:40 -0000 1.5 *************** *** 72,75 **** --- 72,76 ---- private boolean finished=false; private Resolver resolver; + private String encoding = null; public XTMParser(TopicMapSystem tSystem) { *************** *** 86,89 **** --- 87,94 ---- } + public void setEncoding(String encoding) { + this.encoding = encoding; + } + public void setTopicResolver(Resolver resolver){ this.resolver=resolver; *************** *** 98,102 **** if(finished==true) this.tmap=null; ! p.setInput( stream, null ); switch ( p.next() ) { --- 103,107 ---- if(finished==true) this.tmap=null; ! p.setInput( stream, encoding ); switch ( p.next() ) { |
From: Tobias R. <tob...@us...> - 2007-07-09 21:30:47
|
Update of /cvsroot/tmapi-utils/tmapi-utils In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv30490 Modified Files: CHANGES.txt Log Message: Index: CHANGES.txt =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/CHANGES.txt,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** CHANGES.txt 4 Mar 2005 16:44:49 -0000 1.1 --- CHANGES.txt 9 Jul 2007 21:30:45 -0000 1.2 *************** *** 3,4 **** --- 3,7 ---- =================== + 2007-07-09 Tobias Redmann: + - added setEncoding for XTMSerializer to save XTM in any encoding, default is still ISO-8859-1 + |
From: Tobias R. <tob...@us...> - 2007-07-09 21:27:59
|
Update of /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/impexp/xtm In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv28716 Modified Files: XTMSerializer.java Log Message: Added setEncoding to save XTM with any encoding - default is still ISO-8859-1 Index: XTMSerializer.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/impexp/xtm/XTMSerializer.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** XTMSerializer.java 3 Mar 2005 17:33:32 -0000 1.4 --- XTMSerializer.java 9 Jul 2007 21:27:47 -0000 1.5 *************** *** 39,42 **** --- 39,43 ---- private TopicMap tm; private int baselen; + private String encoding = "ISO-8859-1"; public static final String PROPERTY_SUBJECTIDENTIFIERSONLY = "org.tmapi-utils.impexp.xtm.XTMSerializer.subjectIdentifiersOnly"; *************** *** 49,52 **** --- 50,57 ---- setProperty(PROPERTY_ALLIDS, "false"); } + + public void setEncoding(String encoding) { + this.encoding = encoding; + } public void serialize(Writer w, TopicMap tmap) throws TMAPIException { this.tm = tmap; *************** *** 135,139 **** s.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation"," "); s.setOutput(w); ! s.startDocument("ISO-8859-1", null); s.startTag(null, XTMParser.TAG_TOPIC_MAP); --- 140,144 ---- s.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation"," "); s.setOutput(w); ! s.startDocument(this.encoding, null); s.startTag(null, XTMParser.TAG_TOPIC_MAP); *************** *** 144,149 **** public void startTopicMap(OutputStream stream, String base) throws java.io.IOException{ s.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation"," "); ! s.setOutput(stream, "ISO-8859-1"); ! s.startDocument("ISO-8859-1", null); s.startTag(null, XTMParser.TAG_TOPIC_MAP); --- 149,154 ---- public void startTopicMap(OutputStream stream, String base) throws java.io.IOException{ s.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation"," "); ! s.setOutput(stream, this.encoding); ! s.startDocument(this.encoding, null); s.startTag(null, XTMParser.TAG_TOPIC_MAP); *************** *** 160,164 **** s.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation"," "); s.setOutput(writer); ! s.startDocument("ISO-8859-1", null); writeTopic(topic,true); s.endDocument(); --- 165,169 ---- s.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation"," "); s.setOutput(writer); ! s.startDocument(this.encoding, null); writeTopic(topic,true); s.endDocument(); *************** *** 295,299 **** s.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation"," "); s.setOutput(writer); ! s.startDocument("ISO-8859-1", null); writeAssociation(assoc,true); s.endDocument(); --- 300,304 ---- s.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation"," "); s.setOutput(writer); ! s.startDocument(this.encoding, null); writeAssociation(assoc,true); s.endDocument(); |
From: Lars H. <lh...@us...> - 2005-07-12 15:28:53
|
Update of /cvsroot/tmapi-utils/tmapi-utils/web In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4763/web Modified Files: index.html Log Message: Removed strange chars Index: index.html =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/web/index.html,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** index.html 12 Jul 2005 15:26:55 -0000 1.4 --- index.html 12 Jul 2005 15:28:39 -0000 1.5 *************** *** 1,3 **** ! ¿<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> --- 1,3 ---- ! <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
From: Lars H. <lh...@us...> - 2005-07-12 15:27:04
|
Update of /cvsroot/tmapi-utils/tmapi-utils/web In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4000/web Modified Files: index.html Log Message: Smaller SF logo Index: index.html =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/web/index.html,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** index.html 12 Jul 2005 15:20:16 -0000 1.3 --- index.html 12 Jul 2005 15:26:55 -0000 1.4 *************** *** 1,3 **** ! <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> --- 1,3 ---- ! ¿<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> *************** *** 32,36 **** <p>To get started read the <a href="http://tinytim.sourceforge.net/tinyTIM/docs/ar01s03s03.html">tutorial</a>.</p> <p>Project page: <a href="http://www.sourceforge.net/projects/tmapi-utils">http://www.sourceforge.net/projects/tmapi-utils</a> ! <a href="http://sourceforge.net"><img src="http://sourceforge.net/sflogo.php?group_id=115864&type=5" width="210" height="62" border="0" alt="SourceForge.net Logo" /></a> <!-- Main content stops here --> </div> <!-- /content --> --- 32,36 ---- <p>To get started read the <a href="http://tinytim.sourceforge.net/tinyTIM/docs/ar01s03s03.html">tutorial</a>.</p> <p>Project page: <a href="http://www.sourceforge.net/projects/tmapi-utils">http://www.sourceforge.net/projects/tmapi-utils</a> ! <p>The project is hosted by <a href="http://sourceforge.net"><img src="http://sourceforge.net/sflogo.php?group_id=115864&type=1" width="88" height="31" alt="SourceForge" /></a></p> <!-- Main content stops here --> </div> <!-- /content --> |
From: Lars H. <lh...@us...> - 2005-07-12 15:23:17
|
Update of /cvsroot/tmapi-utils/tmapi-utils/web/images In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2274/web/images Modified Files: background.png Log Message: Changed background colour to blue Index: background.png =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/web/images/background.png,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 Binary files /tmp/cvsmmY21O and /tmp/cvs0gEbIl differ |
From: Lars H. <lh...@us...> - 2005-07-12 15:20:27
|
Update of /cvsroot/tmapi-utils/tmapi-utils/web In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1060/web Modified Files: index.html Log Message: Minor changes Index: index.html =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/web/index.html,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** index.html 11 Jul 2005 16:02:22 -0000 1.2 --- index.html 12 Jul 2005 15:20:16 -0000 1.3 *************** *** 13,22 **** </div> <!-- /header --> <div id="navigation"> - <!-- <ul> - <li><a href="#what">What is TMAPI?</a></li> <li><a href="LICENSE.txt">Legal</a></li> </ul> - --> <div class="relatedsites"> Related Sites --- 13,19 ---- *************** *** 31,34 **** --- 28,34 ---- <!-- Main content goes here --> <p>The TMAPI-Utils package contains utility Java classes to work with topic map engines that support the <a href="http://tmapi.org/">TMAPI</a> standard.</p> + <p>In detail the <a href="https://sourceforge.net/project/showfiles.php?group_id=115864&package_id=125774">package</a> currently contains an <a href="http://www.topicmaps.org/xtm/1.0/">XTM</a> + parser and serializer and the topic map engine <a href="https://sf.net/projects/tinytim/">tinyTIM</a>.</p> + <p>To get started read the <a href="http://tinytim.sourceforge.net/tinyTIM/docs/ar01s03s03.html">tutorial</a>.</p> <p>Project page: <a href="http://www.sourceforge.net/projects/tmapi-utils">http://www.sourceforge.net/projects/tmapi-utils</a> <a href="http://sourceforge.net"><img src="http://sourceforge.net/sflogo.php?group_id=115864&type=5" width="210" height="62" border="0" alt="SourceForge.net Logo" /></a> |
From: Lars H. <lh...@us...> - 2005-07-12 15:20:25
|
Update of /cvsroot/tmapi-utils/tmapi-utils/web/styles In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1060/web/styles Modified Files: global.css print.css Log Message: Minor changes Index: global.css =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/web/styles/global.css,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** global.css 11 Jul 2005 15:58:26 -0000 1.1 --- global.css 12 Jul 2005 15:20:16 -0000 1.2 *************** *** 1,7 **** body { color: #000; background-color: #FFF; background-image: url("/images/background.png"); ! background-repeat: repeat-x; background-position: 100% 100%; background-attachment: fixed; --- 1,10 ---- + /* + $Id$ + */ body { color: #000; background-color: #FFF; background-image: url("/images/background.png"); ! background-repeat: repeat-x; background-position: 100% 100%; background-attachment: fixed; *************** *** 57,61 **** #navigation { float: left; ! font-size: small; margin: 0 0 0 1%; width: 16%; --- 60,64 ---- #navigation { float: left; ! font-size: medium; margin: 0 0 0 1%; width: 16%; *************** *** 78,86 **** #navigation .relatedsites { margin-top: 30px; ! font-size: smaller; } #main { ! float: right; width: 75%; margin-right: 2%; --- 81,89 ---- #navigation .relatedsites { margin-top: 30px; ! font-size: small; } #main { ! float: right; width: 75%; margin-right: 2%; Index: print.css =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/web/styles/print.css,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** print.css 11 Jul 2005 15:58:26 -0000 1.1 --- print.css 12 Jul 2005 15:20:16 -0000 1.2 *************** *** 1,2 **** --- 1,5 ---- + /* + $Id$ + */ body { background-color: #FFF; |
From: Lars H. <lh...@us...> - 2005-07-11 16:02:35
|
Update of /cvsroot/tmapi-utils/tmapi-utils/web In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25062/web Modified Files: index.html Log Message: Removed end of comment (-->) Index: index.html =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/web/index.html,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** index.html 11 Jul 2005 15:58:26 -0000 1.1 --- index.html 11 Jul 2005 16:02:22 -0000 1.2 *************** *** 25,29 **** </ul> </div> <!-- /relatedsites --> - --> </div> <!-- /navigation --> <div id="main"> --- 25,28 ---- |
From: Lars H. <lh...@us...> - 2005-07-11 15:58:35
|
Update of /cvsroot/tmapi-utils/tmapi-utils/web In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22998/web Added Files: index.html Log Message: Initial import --- NEW FILE: index.html --- (This appears to be a binary file; contents omitted.) |
From: Lars H. <lh...@us...> - 2005-07-11 15:58:34
|
Update of /cvsroot/tmapi-utils/tmapi-utils/web/styles In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22998/web/styles Added Files: global.css print.css Log Message: Initial import --- NEW FILE: global.css --- body { color: #000; background-color: #FFF; background-image: url("/images/background.png"); background-repeat: repeat-x; background-position: 100% 100%; background-attachment: fixed; margin: 0; font-family: Arial, Helvetica, sans-serif; font-size: medium; } a { color: blue; text-decoration: none; } a:visited { color: blue; } a:hover { text-decoration: underline; } img { border: 0; } p { line-height: 1.4em; } hr { display: none; } /** * Box used for the TMAPI logo */ #header { color: #0083C9; height: 100px; margin: 10px 1% 20px 1%; } #header h1, #header h2 { margin: 0; } #header img { float: left; margin-right: 20px; } #navigation { float: left; font-size: small; margin: 0 0 0 1%; width: 16%; } #navigation ul, #navigation li { margin: 0; padding: 0; } #navigation li { display: block; margin-bottom: 10px; } /** * Subnavigation to related Topic Map sites */ #navigation .relatedsites { margin-top: 30px; font-size: smaller; } #main { float: right; width: 75%; margin-right: 2%; } #content { background-color: #FCFCFC; border-style: solid; border-width: 1px; border-color: #CCC; padding: 10px; } /** * Small navigation breadcrumb on top * of the main content */ #breadcrumb { font-size: small; margin-bottom: 5px; } /** * Box around the application entry */ div.appentry { margin-bottom: 40px; } /** * The application name */ .appentry h3 { margin-bottom: 5px; } /** * The application URL */ .appurl { margin-bottom: 10px; } /** * Application description */ .appdescr { } --- NEW FILE: print.css --- body { background-color: #FFF; color: #000; font-family: Arial, Helvetica, sans-serif; font-size: medium; } img { border: 0; } #navigation, #breadcrumb { display: none; } |
From: Lars H. <lh...@us...> - 2005-07-11 15:58:34
|
Update of /cvsroot/tmapi-utils/tmapi-utils/web/images In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22998/web/images Added Files: background.png Log Message: Initial import --- NEW FILE: background.png --- (This appears to be a binary file; contents omitted.) |
From: Lars H. <lh...@us...> - 2005-07-08 16:27:48
|
Update of /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/impexp/cxtm In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9420/src/org/tmapiutils/impexp/cxtm Modified Files: AssociationComparator.java AssociationRoleComparator.java Canonicalize.java ComparisonException.java Driver.java LocatorComparator.java OccurrenceComparator.java SetComparator.java TopicComparator.java TopicNameComparator.java VariantComparator.java XTMCanonicalizer.java Log Message: Tabs -> Whitespaces Index: XTMCanonicalizer.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/impexp/cxtm/XTMCanonicalizer.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** XTMCanonicalizer.java 5 Mar 2005 17:09:38 -0000 1.1 --- XTMCanonicalizer.java 8 Jul 2005 16:27:22 -0000 1.2 *************** *** 1,593 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * 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 [...1157 lines suppressed...] ! } else if (tmo instanceof TopicMap) { ! reifier = ((TopicMap)tmo).getReifier(); ! } ! if (reifier != null) { ! atts.addAttribute(null, "reifier", "reifier", "CDATA", String.valueOf(m_topicRefMap.get(reifier.getObjectId()))); ! } ! } ! ! public boolean isReifiable(TopicMapObject tmo) { ! return (!(tmo instanceof Topic)); ! } ! ! /** ! * @param b ! */ ! public void setOptWriteSourceLocators(boolean b) { ! m_optWriteSourceLocators = b; ! } ! ! } Index: LocatorComparator.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/impexp/cxtm/LocatorComparator.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** LocatorComparator.java 5 Mar 2005 17:09:38 -0000 1.1 --- LocatorComparator.java 8 Jul 2005 16:27:22 -0000 1.2 *************** *** 1,37 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * 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.tmapiutils.impexp.cxtm; ! ! import java.util.Comparator; ! import org.tmapi.core.Locator; ! ! /** ! * Compares to Locator instances according to the canonical ! * sort rules of the CXTM standard. ! */ ! public class LocatorComparator implements Comparator { ! ! /* (non-Javadoc) ! * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) ! */ ! public int compare(Object o1, Object o2) { ! if (o1 == null && o2 != null) return -1; ! if (o1 != null && o2 == null) return 1; ! if (o1 == null && o2 == null) return 0; ! return ((Locator)o1).getReference().compareTo(((Locator)o2).getReference()); ! } ! ! } --- 1,37 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * 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.tmapiutils.impexp.cxtm; ! ! import java.util.Comparator; ! import org.tmapi.core.Locator; ! ! /** ! * Compares to Locator instances according to the canonical ! * sort rules of the CXTM standard. ! */ ! public class LocatorComparator implements Comparator { ! ! /* (non-Javadoc) ! * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) ! */ ! public int compare(Object o1, Object o2) { ! if (o1 == null && o2 != null) return -1; ! if (o1 != null && o2 == null) return 1; ! if (o1 == null && o2 == null) return 0; ! return ((Locator)o1).getReference().compareTo(((Locator)o2).getReference()); ! } ! ! } Index: AssociationComparator.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/impexp/cxtm/AssociationComparator.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** AssociationComparator.java 5 Mar 2005 17:09:37 -0000 1.1 --- AssociationComparator.java 8 Jul 2005 16:27:22 -0000 1.2 *************** *** 1,56 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * 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.tmapiutils.impexp.cxtm; ! ! import java.util.Comparator; ! ! import org.tmapi.core.Association; ! ! /** ! * A Comparator that compares two Association instances ! * according to the canonical sort order defined by ! * the CXTM standard. ! */ ! public class AssociationComparator implements Comparator { ! ! private static final Comparator topicComp = new TopicComparator(); ! private static final Comparator scopeComp = new SetComparator(topicComp); ! private static final Comparator rolesComp = new AssociationRoleComparator(); ! ! /* (non-Javadoc) ! * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) ! */ ! public int compare(Object o1, Object o2) { ! Association a1 = (Association)o1; ! Association a2 = (Association)o2; ! ! if (o1 == null && o2 != null) return -1; ! if (o1 != null && o2 == null) return 1; ! if (o1 == null && o2 == null) return 0; ! ! int ret = topicComp.compare(a1.getType(), a2.getType()); ! ! if (ret == 0) { ! ret = rolesComp.compare(a1.getAssociationRoles(), a2.getAssociationRoles()); ! } ! ! if (ret == 0) { ! ret = rolesComp.compare(a1.getScope(), a2.getScope()); ! } ! return 0; ! } ! ! } --- 1,56 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * 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.tmapiutils.impexp.cxtm; ! ! import java.util.Comparator; ! ! import org.tmapi.core.Association; ! ! /** ! * A Comparator that compares two Association instances ! * according to the canonical sort order defined by ! * the CXTM standard. ! */ ! public class AssociationComparator implements Comparator { ! ! private static final Comparator topicComp = new TopicComparator(); ! private static final Comparator scopeComp = new SetComparator(topicComp); ! private static final Comparator rolesComp = new AssociationRoleComparator(); ! ! /* (non-Javadoc) ! * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) ! */ ! public int compare(Object o1, Object o2) { ! Association a1 = (Association)o1; ! Association a2 = (Association)o2; ! ! if (o1 == null && o2 != null) return -1; ! if (o1 != null && o2 == null) return 1; ! if (o1 == null && o2 == null) return 0; ! ! int ret = topicComp.compare(a1.getType(), a2.getType()); ! ! if (ret == 0) { ! ret = rolesComp.compare(a1.getAssociationRoles(), a2.getAssociationRoles()); ! } ! ! if (ret == 0) { ! ret = rolesComp.compare(a1.getScope(), a2.getScope()); ! } ! return 0; ! } ! ! } Index: VariantComparator.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/impexp/cxtm/VariantComparator.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** VariantComparator.java 5 Mar 2005 17:09:38 -0000 1.1 --- VariantComparator.java 8 Jul 2005 16:27:22 -0000 1.2 *************** *** 1,66 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * 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.tmapiutils.impexp.cxtm; ! ! import java.util.Comparator; ! ! import org.tmapi.core.Variant; ! ! /** ! * A Comparator implementation which compares TMAPI Variant ! * instances according to the comparison rules of ! * CXTM (ISO 13250-4). ! */ ! public class VariantComparator implements Comparator { ! ! private static final Comparator locComp = new LocatorComparator(); ! private static final Comparator topicComp = new TopicComparator(); ! private static final Comparator scopeComp = new SetComparator(topicComp); ! ! /* (non-Javadoc) ! * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) ! */ ! public int compare(Object o1, Object o2) { ! Variant var1 = (Variant)o1; ! Variant var2 = (Variant)o2; ! ! if (o1 == null && o2 != null) return -1; ! if (o1 != null && o2 == null) return 1; ! if (o1 == null && o2 == null) return 0; ! ! int ret = 0; ! if (var1.getValue() != null && var2.getValue() == null) { ! ret = 1; ! } else if (var1.getValue() == null && var2.getValue() != null) { ! ret = -1; ! } else if (var1.getValue() != null && var2.getValue() != null) { ! ret = var1.getValue().compareTo(var2.getValue()); ! } else { ! ret = locComp.compare(var1.getResource(), var2.getResource()); ! } ! ! if (ret == 0) { ! ret = scopeComp.compare(var1.getScope(), var2.getScope()); ! } ! ! if (ret == 0) { ! ret = topicComp.compare(var1.getTopicName(), var2.getTopicName()); ! } ! ! return ret; ! } ! ! } --- 1,66 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * 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.tmapiutils.impexp.cxtm; ! ! import java.util.Comparator; ! ! import org.tmapi.core.Variant; ! ! /** ! * A Comparator implementation which compares TMAPI Variant ! * instances according to the comparison rules of ! * CXTM (ISO 13250-4). ! */ ! public class VariantComparator implements Comparator { ! ! private static final Comparator locComp = new LocatorComparator(); ! private static final Comparator topicComp = new TopicComparator(); ! private static final Comparator scopeComp = new SetComparator(topicComp); ! ! /* (non-Javadoc) ! * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) ! */ ! public int compare(Object o1, Object o2) { ! Variant var1 = (Variant)o1; ! Variant var2 = (Variant)o2; ! ! if (o1 == null && o2 != null) return -1; ! if (o1 != null && o2 == null) return 1; ! if (o1 == null && o2 == null) return 0; ! ! int ret = 0; ! if (var1.getValue() != null && var2.getValue() == null) { ! ret = 1; ! } else if (var1.getValue() == null && var2.getValue() != null) { ! ret = -1; ! } else if (var1.getValue() != null && var2.getValue() != null) { ! ret = var1.getValue().compareTo(var2.getValue()); ! } else { ! ret = locComp.compare(var1.getResource(), var2.getResource()); ! } ! ! if (ret == 0) { ! ret = scopeComp.compare(var1.getScope(), var2.getScope()); ! } ! ! if (ret == 0) { ! ret = topicComp.compare(var1.getTopicName(), var2.getTopicName()); ! } ! ! return ret; ! } ! ! } Index: TopicNameComparator.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/impexp/cxtm/TopicNameComparator.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TopicNameComparator.java 5 Mar 2005 17:09:38 -0000 1.1 --- TopicNameComparator.java 8 Jul 2005 16:27:22 -0000 1.2 *************** *** 1,53 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * 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.tmapiutils.impexp.cxtm; ! ! import java.util.Comparator; ! ! import org.tmapi.core.TopicName; ! ! /** ! * Compares two TopicName instances according to the ! * canonical sorting rules defined by the CXTM standard. ! */ ! public class TopicNameComparator implements Comparator { ! ! static final Comparator topicComp = new TopicComparator(); ! static final Comparator scopeComp = new SetComparator(topicComp); ! ! /* (non-Javadoc) ! * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) ! */ ! public int compare(Object o1, Object o2) { ! TopicName bn1 = (TopicName)o1; ! TopicName bn2 = (TopicName)o2; ! ! if (o1 == null && o2 != null) return -1; ! if (o1 != null && o2 == null) return 1; ! if (o1 == null && o2 == null) return 0; ! ! int ret = bn1.getValue().compareTo(bn2.getValue()); ! if (ret == 0) { ! // TODO: Type comparison ! ret = scopeComp.compare(bn1.getScope(), bn2.getScope()); ! } ! if (ret == 0) { ! return topicComp.compare(bn1.getTopic(), bn2.getTopic()); ! } ! return ret; ! } ! ! } --- 1,53 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * 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.tmapiutils.impexp.cxtm; ! ! import java.util.Comparator; ! ! import org.tmapi.core.TopicName; ! ! /** ! * Compares two TopicName instances according to the ! * canonical sorting rules defined by the CXTM standard. ! */ ! public class TopicNameComparator implements Comparator { ! ! static final Comparator topicComp = new TopicComparator(); ! static final Comparator scopeComp = new SetComparator(topicComp); ! ! /* (non-Javadoc) ! * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) ! */ ! public int compare(Object o1, Object o2) { ! TopicName bn1 = (TopicName)o1; ! TopicName bn2 = (TopicName)o2; ! ! if (o1 == null && o2 != null) return -1; ! if (o1 != null && o2 == null) return 1; ! if (o1 == null && o2 == null) return 0; ! ! int ret = bn1.getValue().compareTo(bn2.getValue()); ! if (ret == 0) { ! // TODO: Type comparison ! ret = scopeComp.compare(bn1.getScope(), bn2.getScope()); ! } ! if (ret == 0) { ! return topicComp.compare(bn1.getTopic(), bn2.getTopic()); ! } ! return ret; ! } ! ! } Index: Canonicalize.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/impexp/cxtm/Canonicalize.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Canonicalize.java 5 Mar 2005 17:30:08 -0000 1.2 --- Canonicalize.java 8 Jul 2005 16:27:22 -0000 1.3 *************** *** 1,211 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * 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.tmapiutils.impexp.cxtm; ! ! import jargs.gnu.CmdLineParser; ! import jargs.gnu.CmdLineParser.IllegalOptionValueException; ! import jargs.gnu.CmdLineParser.UnknownOptionException; ! ! import java.io.ByteArrayOutputStream; ! import java.io.File; ! import java.io.FileInputStream; ! import java.io.IOException; ! import java.io.InputStream; ! import java.io.OutputStream; ! import java.io.UnsupportedEncodingException; ! ! import org.tmapi.core.TopicMap; ! import org.xml.sax.SAXException; ! ! import org.tmapiutils.impexp.cxtm.utils.SimpleXMLC14N; ! ! /** ! * The command-line driver for CXTMP. ! */ ! public class Canonicalize { ! ! private File m_compareSrc; ! private String m_baseURI; ! private String m_tmFileName; ! private boolean m_insertLinefeeds; ! ! private static CmdLineParser.Option m_driverClassOpt; ! private static CmdLineParser.Option m_baseURIOpt; ! private static CmdLineParser.Option m_compareOpt; ! private Driver m_driver; ! ! ! public static void main(String[] args) { ! Canonicalize theApp = new Canonicalize(args); ! theApp.run(); ! } ! ! public Canonicalize(Driver dr) { ! m_driver = dr; ! } ! ! public Canonicalize(String [] args) { ! CmdLineParser parser = new CmdLineParser(); ! m_driverClassOpt = parser.addStringOption('d', "driver-class"); ! m_baseURIOpt = parser.addStringOption('b', "baseuri"); ! m_compareOpt = parser.addStringOption('c', "compare-to"); ! try { ! parser.parse(args); ! } catch (IllegalOptionValueException e) { ! e.printStackTrace(); ! usage(); ! } catch (UnknownOptionException e) { ! e.printStackTrace(); ! usage(); ! } ! ! if (parser.getOptionValue(m_compareOpt) != null){ ! m_compareSrc = new File((String)parser.getOptionValue(m_compareOpt)); ! if (!m_compareSrc.exists() || !m_compareSrc.canRead()) { ! System.err.println("Cannot read file " + m_compareSrc.getAbsolutePath()); ! System.exit(-1); ! } ! } ! ! // Initialise the TMAPI implementation ! String driverClassName = (String) parser.getOptionValue(m_driverClassOpt); ! System.out.println("Driver class: " + driverClassName); ! try { ! Class driverClass = Class.forName(driverClassName); ! m_driver = (Driver)driverClass.newInstance(); ! m_driver.initialise(System.getProperties()); ! } catch (Exception ex) { ! System.err.println("Error initialising topic map system."); ! ex.printStackTrace(); ! System.exit(-1); ! } ! ! m_baseURI = (String) parser.getOptionValue(m_baseURIOpt); ! ! String[] rem = parser.getRemainingArgs(); ! if (rem == null) { ! System.out.println("No input topic map file name specified."); ! usage(); ! } ! ! m_tmFileName = parser.getRemainingArgs()[0]; ! } ! ! public void run() { ! try { ! // TODO: If src locator is a URL, use a URL stream ! File f = new File(m_tmFileName); ! InputStream in = new FileInputStream(f); ! if (m_baseURI == null) { ! m_baseURI = f.toURL().toString(); ! } ! if (m_compareSrc == null) { ! canonicalize(in, m_baseURI, System.out); ! } else { ! ByteArrayOutputStream expected = new ByteArrayOutputStream(); ! int tmp; ! InputStream expectedStr = new FileInputStream(m_compareSrc); ! while ((tmp = expectedStr.read()) != -1) { ! expected.write(tmp); ! } ! StringBuffer actual = new StringBuffer(); ! int mismatchAt = canonicalize(in, m_baseURI, expected.toByteArray(), actual); ! if (mismatchAt < 0) { ! System.exit(0); ! } else { ! System.err.println("Canonicalized form of input does not match expected value."); ! System.err.println("Expected: " + expected.toString("UTF-8")); ! System.err.println("Actual: " + actual.toString()); ! System.exit(-1); ! } ! } ! } catch (Exception ex) { ! System.err.println("Error caught during canonicalization: "+ ex.getMessage()); ! ex.printStackTrace(); ! System.exit(-1); ! } ! } ! ! private int compare(byte[] expected, byte[] actual) ! throws IOException, ComparisonException ! { ! int lineCount = 1; ! int charCount = 1; ! if (expected.length > actual.length) return actual.length; ! for (int ix = 0; ix < expected.length; ix++) { ! if (ix > actual.length) { ! throw new ComparisonException("Output shorter than expected.", lineCount, charCount); ! } ! if (expected[ix] != actual[ix]) { ! throw new ComparisonException("Expected " + (char)expected[ix] + " found " + (char)actual[ix], lineCount, charCount); ! } ! if (expected[ix] == 10) { ! lineCount++; ! charCount = 1; ! } else { ! charCount++; ! } ! } ! return -1; ! } ! ! public void canonicalize(InputStream in, String baseURI, OutputStream out) { ! TopicMap tm = null; ! try { ! tm = m_driver.importXTM(in, baseURI); ! } catch (Exception ex) { ! System.err.println("Error importing source XTM."); ! ex.printStackTrace(); ! System.exit(-1); ! } ! try { ! SimpleXMLC14N xmlCanonicalizer = new SimpleXMLC14N(out); ! xmlCanonicalizer.setInsertLinefeeds(m_insertLinefeeds); ! XTMCanonicalizer c = new XTMCanonicalizer(xmlCanonicalizer); ! c.canonicalize(tm); ! } catch (SAXException ex) { ! System.out.println("Error during canonicalisation."); ! ex.printStackTrace(); ! } catch (UnsupportedEncodingException ex) { ! System.out.println("Cannot write canonical output. " + ex.toString()); ! } catch (Exception ex) { ! System.out.println("Error during canonicalisation."); ! ex.printStackTrace(); ! } ! } ! ! public int canonicalize(InputStream in, String baseURI, byte[] expected, StringBuffer actual) throws IOException, ComparisonException { ! ByteArrayOutputStream bos = new ByteArrayOutputStream(); ! canonicalize(in, baseURI, bos); ! if (actual != null) { ! actual.append(bos.toString()); ! } ! return compare(expected, bos.toByteArray()); ! } ! ! private void usage() { ! System.out.println("Usage: java org.tmapiutils.impexp.cxtm.Canonicalize -d <driver class name> [-b <base uri>] [-c <cxtm comparison file>] topicmap_filename"); ! System.exit(-1); ! } ! ! public void setDriver(Driver dr) { ! m_driver = dr; ! } ! ! public void setInsertLinefeeds(boolean b) { ! m_insertLinefeeds = b; ! } ! } --- 1,211 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * 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.tmapiutils.impexp.cxtm; ! ! import jargs.gnu.CmdLineParser; ! import jargs.gnu.CmdLineParser.IllegalOptionValueException; ! import jargs.gnu.CmdLineParser.UnknownOptionException; ! ! import java.io.ByteArrayOutputStream; ! import java.io.File; ! import java.io.FileInputStream; ! import java.io.IOException; ! import java.io.InputStream; ! import java.io.OutputStream; ! import java.io.UnsupportedEncodingException; ! ! import org.tmapi.core.TopicMap; ! import org.xml.sax.SAXException; ! ! import org.tmapiutils.impexp.cxtm.utils.SimpleXMLC14N; ! ! /** ! * The command-line driver for CXTMP. ! */ ! public class Canonicalize { ! ! private File m_compareSrc; ! private String m_baseURI; ! private String m_tmFileName; ! private boolean m_insertLinefeeds; ! ! private static CmdLineParser.Option m_driverClassOpt; ! private static CmdLineParser.Option m_baseURIOpt; ! private static CmdLineParser.Option m_compareOpt; ! private Driver m_driver; ! ! ! public static void main(String[] args) { ! Canonicalize theApp = new Canonicalize(args); ! theApp.run(); ! } ! ! public Canonicalize(Driver dr) { ! m_driver = dr; ! } ! ! public Canonicalize(String [] args) { ! CmdLineParser parser = new CmdLineParser(); ! m_driverClassOpt = parser.addStringOption('d', "driver-class"); ! m_baseURIOpt = parser.addStringOption('b', "baseuri"); ! m_compareOpt = parser.addStringOption('c', "compare-to"); ! try { ! parser.parse(args); ! } catch (IllegalOptionValueException e) { ! e.printStackTrace(); ! usage(); ! } catch (UnknownOptionException e) { ! e.printStackTrace(); ! usage(); ! } ! ! if (parser.getOptionValue(m_compareOpt) != null){ ! m_compareSrc = new File((String)parser.getOptionValue(m_compareOpt)); ! if (!m_compareSrc.exists() || !m_compareSrc.canRead()) { ! System.err.println("Cannot read file " + m_compareSrc.getAbsolutePath()); ! System.exit(-1); ! } ! } ! ! // Initialise the TMAPI implementation ! String driverClassName = (String) parser.getOptionValue(m_driverClassOpt); ! System.out.println("Driver class: " + driverClassName); ! try { ! Class driverClass = Class.forName(driverClassName); ! m_driver = (Driver)driverClass.newInstance(); ! m_driver.initialise(System.getProperties()); ! } catch (Exception ex) { ! System.err.println("Error initialising topic map system."); ! ex.printStackTrace(); ! System.exit(-1); ! } ! ! m_baseURI = (String) parser.getOptionValue(m_baseURIOpt); ! ! String[] rem = parser.getRemainingArgs(); ! if (rem == null) { ! System.out.println("No input topic map file name specified."); ! usage(); ! } ! ! m_tmFileName = parser.getRemainingArgs()[0]; ! } ! ! public void run() { ! try { ! // TODO: If src locator is a URL, use a URL stream ! File f = new File(m_tmFileName); ! InputStream in = new FileInputStream(f); ! if (m_baseURI == null) { ! m_baseURI = f.toURL().toString(); ! } ! if (m_compareSrc == null) { ! canonicalize(in, m_baseURI, System.out); ! } else { ! ByteArrayOutputStream expected = new ByteArrayOutputStream(); ! int tmp; ! InputStream expectedStr = new FileInputStream(m_compareSrc); ! while ((tmp = expectedStr.read()) != -1) { ! expected.write(tmp); ! } ! StringBuffer actual = new StringBuffer(); ! int mismatchAt = canonicalize(in, m_baseURI, expected.toByteArray(), actual); ! if (mismatchAt < 0) { ! System.exit(0); ! } else { ! System.err.println("Canonicalized form of input does not match expected value."); ! System.err.println("Expected: " + expected.toString("UTF-8")); ! System.err.println("Actual: " + actual.toString()); ! System.exit(-1); ! } ! } ! } catch (Exception ex) { ! System.err.println("Error caught during canonicalization: "+ ex.getMessage()); ! ex.printStackTrace(); ! System.exit(-1); ! } ! } ! ! private int compare(byte[] expected, byte[] actual) ! throws IOException, ComparisonException ! { ! int lineCount = 1; ! int charCount = 1; ! if (expected.length > actual.length) return actual.length; ! for (int ix = 0; ix < expected.length; ix++) { ! if (ix > actual.length) { ! throw new ComparisonException("Output shorter than expected.", lineCount, charCount); ! } ! if (expected[ix] != actual[ix]) { ! throw new ComparisonException("Expected " + (char)expected[ix] + " found " + (char)actual[ix], lineCount, charCount); ! } ! if (expected[ix] == 10) { ! lineCount++; ! charCount = 1; ! } else { ! charCount++; ! } ! } ! return -1; ! } ! ! public void canonicalize(InputStream in, String baseURI, OutputStream out) { ! TopicMap tm = null; ! try { ! tm = m_driver.importXTM(in, baseURI); ! } catch (Exception ex) { ! System.err.println("Error importing source XTM."); ! ex.printStackTrace(); ! System.exit(-1); ! } ! try { ! SimpleXMLC14N xmlCanonicalizer = new SimpleXMLC14N(out); ! xmlCanonicalizer.setInsertLinefeeds(m_insertLinefeeds); ! XTMCanonicalizer c = new XTMCanonicalizer(xmlCanonicalizer); ! c.canonicalize(tm); ! } catch (SAXException ex) { ! System.out.println("Error during canonicalisation."); ! ex.printStackTrace(); ! } catch (UnsupportedEncodingException ex) { ! System.out.println("Cannot write canonical output. " + ex.toString()); ! } catch (Exception ex) { ! System.out.println("Error during canonicalisation."); ! ex.printStackTrace(); ! } ! } ! ! public int canonicalize(InputStream in, String baseURI, byte[] expected, StringBuffer actual) throws IOException, ComparisonException { ! ByteArrayOutputStream bos = new ByteArrayOutputStream(); ! canonicalize(in, baseURI, bos); ! if (actual != null) { ! actual.append(bos.toString()); ! } ! return compare(expected, bos.toByteArray()); ! } ! ! private void usage() { ! System.out.println("Usage: java org.tmapiutils.impexp.cxtm.Canonicalize -d <driver class name> [-b <base uri>] [-c <cxtm comparison file>] topicmap_filename"); ! System.exit(-1); ! } ! ! public void setDriver(Driver dr) { ! m_driver = dr; ! } ! ! public void setInsertLinefeeds(boolean b) { ! m_insertLinefeeds = b; ! } ! } Index: ComparisonException.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/impexp/cxtm/ComparisonException.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ComparisonException.java 5 Mar 2005 17:09:38 -0000 1.1 --- ComparisonException.java 8 Jul 2005 16:27:22 -0000 1.2 *************** *** 1,34 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * 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.tmapiutils.impexp.cxtm; ! ! /** ! * Exception raised when comparison of generated CXTM output ! * and expected CXTM output fails. ! */ ! public class ComparisonException extends Exception { ! private String m_msg; ! private int m_line; ! private int m_ch; ! ! public ComparisonException(String msg, int lineCount, int charCount) { ! super(String.valueOf(lineCount) + "," + String.valueOf(charCount) + ": " + msg); ! m_msg = msg; ! m_line =lineCount; ! m_ch = charCount; ! } ! ! } --- 1,34 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * 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.tmapiutils.impexp.cxtm; ! ! /** ! * Exception raised when comparison of generated CXTM output ! * and expected CXTM output fails. ! */ ! public class ComparisonException extends Exception { ! private String m_msg; ! private int m_line; ! private int m_ch; ! ! public ComparisonException(String msg, int lineCount, int charCount) { ! super(String.valueOf(lineCount) + "," + String.valueOf(charCount) + ": " + msg); ! m_msg = msg; ! m_line =lineCount; ! m_ch = charCount; ! } ! ! } Index: SetComparator.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/impexp/cxtm/SetComparator.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SetComparator.java 5 Mar 2005 17:09:38 -0000 1.1 --- SetComparator.java 8 Jul 2005 16:27:22 -0000 1.2 *************** *** 1,57 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * 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.tmapiutils.impexp.cxtm; ! ! import java.util.Collection; ! import java.util.Comparator; ! import java.util.Iterator; ! import java.util.TreeSet; ! ! /** ! * Compares two sets of objects according to the collection ! * comparison algorithm specified by the CXTM standard. ! */ ! public class SetComparator implements Comparator { ! ! private Comparator m_ic; ! ! public SetComparator(Comparator instanceComparator) { ! m_ic = instanceComparator; ! } ! ! /* (non-Javadoc) ! * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) ! */ ! public int compare(Object o1, Object o2) { ! if (!(o1 instanceof Collection) || !(o2 instanceof Collection)) { ! throw new RuntimeException("CollectionComparator invoked with a parameter that is not a Collection"); ! } ! int ret = ((Collection)o2).size() - ((Collection)o1).size(); ! if (ret == 0) { ! TreeSet ts1 = new TreeSet(m_ic); ! ts1.addAll((Collection)o1); ! TreeSet ts2 = new TreeSet(m_ic); ! ts2.addAll((Collection)o2); ! Iterator it1 = ts1.iterator(); ! Iterator it2 = ts2.iterator(); ! while ((ret == 0) && (it1.hasNext())) { ! ret = m_ic.compare(it1.next(), it2.next()); ! } ! } ! return ret; ! } ! ! } --- 1,57 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * 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.tmapiutils.impexp.cxtm; ! ! import java.util.Collection; ! import java.util.Comparator; ! import java.util.Iterator; ! import java.util.TreeSet; ! ! /** ! * Compares two sets of objects according to the collection ! * comparison algorithm specified by the CXTM standard. ! */ ! public class SetComparator implements Comparator { ! ! private Comparator m_ic; ! ! public SetComparator(Comparator instanceComparator) { ! m_ic = instanceComparator; ! } ! ! /* (non-Javadoc) ! * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) ! */ ! public int compare(Object o1, Object o2) { ! if (!(o1 instanceof Collection) || !(o2 instanceof Collection)) { ! throw new RuntimeException("CollectionComparator invoked with a parameter that is not a Collection"); ! } ! int ret = ((Collection)o2).size() - ((Collection)o1).size(); ! if (ret == 0) { ! TreeSet ts1 = new TreeSet(m_ic); ! ts1.addAll((Collection)o1); ! TreeSet ts2 = new TreeSet(m_ic); ! ts2.addAll((Collection)o2); ! Iterator it1 = ts1.iterator(); ! Iterator it2 = ts2.iterator(); ! while ((ret == 0) && (it1.hasNext())) { ! ret = m_ic.compare(it1.next(), it2.next()); ! } ! } ! return ret; ! } ! ! } Index: AssociationRoleComparator.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/impexp/cxtm/AssociationRoleComparator.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** AssociationRoleComparator.java 5 Mar 2005 17:09:38 -0000 1.1 --- AssociationRoleComparator.java 8 Jul 2005 16:27:22 -0000 1.2 *************** *** 1,53 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * 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.tmapiutils.impexp.cxtm; ! ! import java.util.Comparator; ! ! import org.tmapi.core.AssociationRole; ! ! /** ! * Compares two AssociationRole instances according to the ! * canonical sorting algorithm of CXTM. ! */ ! public class AssociationRoleComparator implements Comparator { ! ! private static final Comparator topicComp = new TopicComparator(); ! private static final Comparator scopeComp = new SetComparator(topicComp); ! ! /* (non-Javadoc) ! * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) ! */ ! public int compare(Object o1, Object o2) { ! AssociationRole m1 = (AssociationRole)o1; ! AssociationRole m2 = (AssociationRole)o2; ! ! if (o1 == null && o2 != null) return -1; ! if (o1 != null && o2 == null) return 1; ! if (o1 == null && o2 == null) return 0; ! ! int ret = topicComp.compare(m1.getPlayer(), m2.getPlayer()); ! if (ret == 0) { ! ret = topicComp.compare(m1.getType(), m2.getType()); ! } ! if (ret == 0) { ! // TODO: Need to rework the spec here. ! ret = new AssociationComparator().compare(m1.getAssociation(), m2.getAssociation()); ! } ! return ret; ! } ! ! } --- 1,53 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * 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.tmapiutils.impexp.cxtm; ! ! import java.util.Comparator; ! ! import org.tmapi.core.AssociationRole; ! ! /** ! * Compares two AssociationRole instances according to the ! * canonical sorting algorithm of CXTM. ! */ ! public class AssociationRoleComparator implements Comparator { ! ! private static final Comparator topicComp = new TopicComparator(); ! private static final Comparator scopeComp = new SetComparator(topicComp); ! ! /* (non-Javadoc) ! * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) ! */ ! public int compare(Object o1, Object o2) { ! AssociationRole m1 = (AssociationRole)o1; ! AssociationRole m2 = (AssociationRole)o2; ! ! if (o1 == null && o2 != null) return -1; ! if (o1 != null && o2 == null) return 1; ! if (o1 == null && o2 == null) return 0; ! ! int ret = topicComp.compare(m1.getPlayer(), m2.getPlayer()); ! if (ret == 0) { ! ret = topicComp.compare(m1.getType(), m2.getType()); ! } ! if (ret == 0) { ! // TODO: Need to rework the spec here. ! ret = new AssociationComparator().compare(m1.getAssociation(), m2.getAssociation()); ! } ! return ret; ! } ! ! } Index: OccurrenceComparator.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/impexp/cxtm/OccurrenceComparator.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** OccurrenceComparator.java 5 Mar 2005 17:09:38 -0000 1.1 --- OccurrenceComparator.java 8 Jul 2005 16:27:22 -0000 1.2 *************** *** 1,69 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * 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.tmapiutils.impexp.cxtm; ! ! import java.util.Comparator; ! ! import org.tmapi.core.Occurrence; ! ! /** ! * Compares two Occurrence instances according to the ! * canonical sorting rules of the CXTM standard. ! */ ! public class OccurrenceComparator implements Comparator { ! ! private static final Comparator locComp = new LocatorComparator(); ! private static final Comparator topicComp = new TopicComparator(); ! private static final Comparator scopeComp = new SetComparator(topicComp); ! ! /* (non-Javadoc) ! * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) ! */ ! public int compare(Object o1, Object o2) { ! Occurrence occ1 = (Occurrence)o1; ! Occurrence occ2 = (Occurrence)o2; ! ! if (o1 == null && o2 != null) return -1; ! if (o1 != null && o2 == null) return 1; ! if (o1 == null && o2 == null) return 0; ! ! int ret = 0; ! if (occ1.getValue() != null && occ2.getValue() == null) { ! ret = 1; ! } else if (occ1.getValue() == null && occ2.getValue() != null) { ! ret = -1; ! } else if (occ1.getValue() != null && occ2.getValue() != null) { ! ret = occ1.getValue().compareTo(occ2.getValue()); ! } else { ! ret = locComp.compare(occ1.getResource(), occ2.getResource()); ! } ! ! if (ret == 0) { ! ret = topicComp.compare(occ1.getType(), occ2.getType()); ! } ! ! if (ret == 0) { ! ret = scopeComp.compare(occ1.getScope(), occ2.getScope()); ! } ! ! if (ret == 0) { ! ret = topicComp.compare(occ1.getTopic(), occ2.getTopic()); ! } ! ! return ret; ! } ! ! } --- 1,69 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * 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.tmapiutils.impexp.cxtm; ! ! import java.util.Comparator; ! ! import org.tmapi.core.Occurrence; ! ! /** ! * Compares two Occurrence instances according to the ! * canonical sorting rules of the CXTM standard. ! */ ! public class OccurrenceComparator implements Comparator { ! ! private static final Comparator locComp = new LocatorComparator(); ! private static final Comparator topicComp = new TopicComparator(); ! private static final Comparator scopeComp = new SetComparator(topicComp); ! ! /* (non-Javadoc) ! * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) ! */ ! public int compare(Object o1, Object o2) { ! Occurrence occ1 = (Occurrence)o1; ! Occurrence occ2 = (Occurrence)o2; ! ! if (o1 == null && o2 != null) return -1; ! if (o1 != null && o2 == null) return 1; ! if (o1 == null && o2 == null) return 0; ! ! int ret = 0; ! if (occ1.getValue() != null && occ2.getValue() == null) { ! ret = 1; ! } else if (occ1.getValue() == null && occ2.getValue() != null) { ! ret = -1; ! } else if (occ1.getValue() != null && occ2.getValue() != null) { ! ret = occ1.getValue().compareTo(occ2.getValue()); ! } else { ! ret = locComp.compare(occ1.getResource(), occ2.getResource()); ! } ! ! if (ret == 0) { ! ret = topicComp.compare(occ1.getType(), occ2.getType()); ! } ! ! if (ret == 0) { ! ret = scopeComp.compare(occ1.getScope(), occ2.getScope()); ! } ! ! if (ret == 0) { ! ret = topicComp.compare(occ1.getTopic(), occ2.getTopic()); ! } ! ! return ret; ! } ! ! } Index: Driver.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/impexp/cxtm/Driver.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Driver.java 5 Mar 2005 17:09:38 -0000 1.1 --- Driver.java 8 Jul 2005 16:27:22 -0000 1.2 *************** *** 1,51 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * 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.tmapiutils.impexp.cxtm; ! ! import java.io.InputStream; ! import java.util.Properties; ! ! import org.tmapi.core.TopicMap; ! ! /** ! * The interface to be implemented by the Driver that ! * enables CXTMP to talk to a topic map processor. ! */ ! public interface Driver { ! ! /** ! * This method is invoked by the CXTMP processor after ! * loading the Driver class and before any calls to ! * the importXTM method. ! * @param props configuration properties that the Driver can ! * use to initialise the underlying topic map processor ! * @throws Exception if the initialisation of the topic map ! * processor fails for any reason. ! */ ! public void initialise(Properties props) throws Exception; ! ! /** ! * This method is invoked by CXTMP to load a topic map ! * into the topic map processor. ! * @param src the input stream from which the topic map can be read ! * @param baseURI a hint to the base URI to be assigned to the topic map on import. ! * A Driver implementation may choose to ignore this value. ! * @return the TMAPI TopicMap instance that represents the topic map processor's ! * fully merged model of the parsed input ! * @throws Exception if the import fails for any reason. ! */ ! public TopicMap importXTM(InputStream src, String baseURI) throws Exception; ! } --- 1,51 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * 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.tmapiutils.impexp.cxtm; ! ! import java.io.InputStream; ! import java.util.Properties; ! ! import org.tmapi.core.TopicMap; ! ! /** ! * The interface to be implemented by the Driver that ! * enables CXTMP to talk to a topic map processor. ! */ ! public interface Driver { ! ! /** ! * This method is invoked by the CXTMP processor after ! * loading the Driver class and before any calls to ! * the importXTM method. ! * @param props configuration properties that the Driver can ! * use to initialise the underlying topic map processor ! * @throws Exception if the initialisation of the topic map ! * processor fails for any reason. ! */ ! public void initialise(Properties props) throws Exception; ! ! /** ! * This method is invoked by CXTMP to load a topic map ! * into the topic map processor. ! * @param src the input stream from which the topic map can be read ! * @param baseURI a hint to the base URI to be assigned to the topic map on import. ! * A Driver implementation may choose to ignore this value. ! * @return the TMAPI TopicMap instance that represents the topic map processor's ! * fully merged model of the parsed input ! * @throws Exception if the import fails for any reason. ! */ ! public TopicMap importXTM(InputStream src, String baseURI) throws Exception; ! } Index: TopicComparator.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/impexp/cxtm/TopicComparator.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TopicComparator.java 5 Mar 2005 17:09:38 -0000 1.1 --- TopicComparator.java 8 Jul 2005 16:27:22 -0000 1.2 *************** *** 1,61 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * 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.tmapiutils.impexp.cxtm; ! ! import java.util.Comparator; ! ! import org.tmapi.core.Locator; ! import org.tmapi.core.Topic; ! ! /** ! * Implements the topic comparison algorithm defined by ! * the CXTM specification. ! */ ! public class TopicComparator implements Comparator { ! ! /* (non-Javadoc) ! * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) ! */ ! public int compare(Object o1, Object o2) { ! if (!(o1 instanceof Topic) || !(o2 instanceof Topic)) { ! throw new IllegalArgumentException("TopicComparator invoked with parameter that is not a Topic."); ! } ! ! Topic t1 = (Topic)o1; ! Topic t2 = (Topic)o2; ! Comparator locatorSetComparator = new SetComparator(new LocatorComparator()); ! int ret = locatorSetComparator.compare(t1.getSourceLocators(), t2.getSourceLocators()); ! if (ret == 0) { ! ret = locatorSetComparator.compare(t1.getSubjectIdentifiers(), t2.getSubjectIdentifiers()); ! } ! if (ret == 0) { ! Locator l1 = t1.getSubjectLocator(); ! Locator l2 =t2.getSubjectLocator(); ! if (l1 == null && l2 != null) { ! return -1; ! } else if (l1 != null && l2 == null) { ! return 1; ! } else { ! return new LocatorComparator().compare(l1, l2); ! } ! } ! if (ret == 0) { ! throw new RuntimeException("Unable to compare topics - perhaps they are the same ?"); ! } ! return ret; ! } ! ! } --- 1,61 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * 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.tmapiutils.impexp.cxtm; ! ! import java.util.Comparator; ! ! import org.tmapi.core.Locator; ! import org.tmapi.core.Topic; ! ! /** ! * Implements the topic comparison algorithm defined by ! * the CXTM specification. ! */ ! public class TopicComparator implements Comparator { ! ! /* (non-Javadoc) ! * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) ! */ ! public int compare(Object o1, Object o2) { ! if (!(o1 instanceof Topic) || !(o2 instanceof Topic)) { ! throw new IllegalArgumentException("TopicComparator invoked with parameter that is not a Topic."); ! } ! ! Topic t1 = (Topic)o1; ! Topic t2 = (Topic)o2; ! Comparator locatorSetComparator = new SetComparator(new LocatorComparator()); ! int ret = locatorSetComparator.compare(t1.getSourceLocators(), t2.getSourceLocators()); ! if (ret == 0) { ! ret = locatorSetComparator.compare(t1.getSubjectIdentifiers(), t2.getSubjectIdentifiers()); ! } ! if (ret == 0) { ! Locator l1 = t1.getSubjectLocator(); ! Locator l2 =t2.getSubjectLocator(); ! if (l1 == null && l2 != null) { ! return -1; ! } else if (l1 != null && l2 == null) { ! return 1; ! } else { ! return new LocatorComparator().compare(l1, l2); ! } ! } ! if (ret == 0) { ! throw new RuntimeException("Unable to compare topics - perhaps they are the same ?"); ! } ! return ret; ! } ! ! } |
From: Lars H. <lh...@us...> - 2005-07-08 16:27:32
|
Update of /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/impexp/cxtm/utils In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9420/src/org/tmapiutils/impexp/cxtm/utils Modified Files: SimpleXMLC14N.java Log Message: Tabs -> Whitespaces Index: SimpleXMLC14N.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/impexp/cxtm/utils/SimpleXMLC14N.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SimpleXMLC14N.java 5 Mar 2005 17:09:38 -0000 1.1 --- SimpleXMLC14N.java 8 Jul 2005 16:27:23 -0000 1.2 *************** *** 1,189 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * 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.tmapiutils.impexp.cxtm.utils; ! ! import java.io.IOException; ! import java.io.OutputStream; ! import java.io.OutputStreamWriter; ! import java.io.UnsupportedEncodingException; ! import java.io.Writer; ! import java.util.Iterator; ! import java.util.TreeSet; ! ! import org.xml.sax.Attributes; ! import org.xml.sax.ContentHandler; ! import org.xml.sax.Locator; ! import org.xml.sax.SAXException; ! ! /** ! * A very simple implementation of XML canonicalisation ! * this implementation is really only designed to handle ! * the output generated by the XTMCanonicalizer class ! * and should not be used for general XML canonicalisation! ! */ ! public class SimpleXMLC14N implements ContentHandler { ! ! private StringBuffer m_charBuf; ! private OutputStream m_outputStream; ! private Writer m_out; ! private boolean m_insertLinefeeds = false; ! private boolean m_inDocument = false; ! private static final String STAGO = "<"; ! private static final String STAGC = ">"; ! private static final String ETAGO = "</"; ! private static final String ETAGC = ">"; ! private static final int LF = 10; ! ! public SimpleXMLC14N(OutputStream os) throws UnsupportedEncodingException ! { ! m_outputStream = os; ! m_out = new OutputStreamWriter(os, "UTF-8"); ! } ! ! public void setInsertLinefeeds(boolean b) { ! m_insertLinefeeds = b; ! } ! ! /* (non-Javadoc) ! * @see org.xml.sax.ContentHandler#endDocument() ! */ ! public void endDocument() throws SAXException { ! try { ! m_out.flush(); ! } catch (IOException ex) { ! throw new SAXException(ex); ! } ! } ! ! /* (non-Javadoc) ! * @see org.xml.sax.ContentHandler#startDocument() ! */ ! public void startDocument() throws SAXException { ! } ! ! /* (non-Javadoc) ! * @see org.xml.sax.ContentHandler#characters(char[], int, int) ! */ ! public void characters(char[] ch, int start, int length) ! throws SAXException { ! if (m_charBuf == null) m_charBuf = new StringBuffer(); ! m_charBuf.append(ch, start, length); ! } ! ! /* (non-Javadoc) ! * @see org.xml.sax.ContentHandler#ignorableWhitespace(char[], int, int) ! */ ! public void ignorableWhitespace(char[] ch, int start, int length) ! throws SAXException { ! // Ignore ignorable whitespace ! } ! ! /* (non-Javadoc) ! * @see org.xml.sax.ContentHandler#endPrefixMapping(java.lang.String) ! */ ! public void endPrefixMapping(String prefix) throws SAXException { ! throw new UnsupportedOperationException("This canonicalizer does not process namespaces."); ! } ! ! /* (non-Javadoc) ! * @see org.xml.sax.ContentHandler#skippedEntity(java.lang.String) ! */ ! public void skippedEntity(String name) throws SAXException { ! throw new UnsupportedOperationException("This canonicalizer does not process entities."); ! } ! ! /* (non-Javadoc) ! * @see org.xml.sax.ContentHandler#setDocumentLocator(org.xml.sax.Locator) ! */ ! public void setDocumentLocator(Locator locator) { ! // NO-OP ! } ! ! /* (non-Javadoc) ! * @see org.xml.sax.ContentHandler#processingInstruction(java.lang.String, java.lang.String) ! */ ! public void processingInstruction(String target, String data) ! throws SAXException { ! throw new UnsupportedOperationException("This canonicalizer does not process namespaces."); ! } ! ! /* (non-Javadoc) ! * @see org.xml.sax.ContentHandler#startPrefixMapping(java.lang.String, java.lang.String) ! */ ! public void startPrefixMapping(String prefix, String uri) ! throws SAXException { ! throw new UnsupportedOperationException("This canonicalizer does not process namespaces."); ! } ! ! /* (non-Javadoc) ! * @see org.xml.sax.ContentHandler#endElement(java.lang.String, java.lang.String, java.lang.String) ! */ ! public void endElement(String namespaceURI, String localName, String qName) ! throws SAXException { ! try { ! if (m_charBuf != null) { ! m_out.write(normalize(m_charBuf.toString())); ! } else { ! m_out.write(LF); ! } ! m_out.write(ETAGO); ! m_out.write(qName); ! m_out.write(ETAGC); ! m_charBuf = null; ! } catch (IOException ex) { ! throw new SAXException(ex); ! } ! } ! ! /* (non-Javadoc) ! * @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes) ! */ ! public void startElement( ! String namespaceURI, ! String localName, ! String qName, ! Attributes atts) ! throws SAXException { ! try { ! if (m_inDocument) m_out.write(LF); ! m_out.write(STAGO); ! m_out.write(normalize(qName)); ! if ((atts != null) && (atts.getLength() > 0)) { ! TreeSet ts = new TreeSet(); ! for (int i = 0; i < atts.getLength(); i++) { ! ts.add(atts.getQName(i)); ! } ! Iterator it = ts.iterator(); ! while (it.hasNext()) { ! String qname = (String)it.next(); ! m_out.write(' '); ! m_out.write(normalize(qname)); ! m_out.write("=\""); ! m_out.write(atts.getValue(qname)); ! m_out.write('"'); ! } ! } ! m_out.write(STAGC); ! m_inDocument = true; ! } catch (IOException ex) { ! throw new SAXException(ex); ! } ! } ! ! private String normalize(String str) { ! return str; ! } ! } --- 1,189 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * 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.tmapiutils.impexp.cxtm.utils; ! ! import java.io.IOException; ! import java.io.OutputStream; ! import java.io.OutputStreamWriter; ! import java.io.UnsupportedEncodingException; ! import java.io.Writer; ! import java.util.Iterator; ! import java.util.TreeSet; ! ! import org.xml.sax.Attributes; ! import org.xml.sax.ContentHandler; ! import org.xml.sax.Locator; ! import org.xml.sax.SAXException; ! ! /** ! * A very simple implementation of XML canonicalisation ! * this implementation is really only designed to handle ! * the output generated by the XTMCanonicalizer class ! * and should not be used for general XML canonicalisation! ! */ ! public class SimpleXMLC14N implements ContentHandler { ! ! private StringBuffer m_charBuf; ! private OutputStream m_outputStream; ! private Writer m_out; ! private boolean m_insertLinefeeds = false; ! private boolean m_inDocument = false; ! private static final String STAGO = "<"; ! private static final String STAGC = ">"; ! private static final String ETAGO = "</"; ! private static final String ETAGC = ">"; ! private static final int LF = 10; ! ! public SimpleXMLC14N(OutputStream os) throws UnsupportedEncodingException ! { ! m_outputStream = os; ! m_out = new OutputStreamWriter(os, "UTF-8"); ! } ! ! public void setInsertLinefeeds(boolean b) { ! m_insertLinefeeds = b; ! } ! ! /* (non-Javadoc) ! * @see org.xml.sax.ContentHandler#endDocument() ! */ ! public void endDocument() throws SAXException { ! try { ! m_out.flush(); ! } catch (IOException ex) { ! throw new SAXException(ex); ! } ! } ! ! /* (non-Javadoc) ! * @see org.xml.sax.ContentHandler#startDocument() ! */ ! public void startDocument() throws SAXException { ! } ! ! /* (non-Javadoc) ! * @see org.xml.sax.ContentHandler#characters(char[], int, int) ! */ ! public void characters(char[] ch, int start, int length) ! throws SAXException { ! if (m_charBuf == null) m_charBuf = new StringBuffer(); ! m_charBuf.append(ch, start, length); ! } ! ! /* (non-Javadoc) ! * @see org.xml.sax.ContentHandler#ignorableWhitespace(char[], int, int) ! */ ! public void ignorableWhitespace(char[] ch, int start, int length) ! throws SAXException { ! // Ignore ignorable whitespace ! } ! ! /* (non-Javadoc) ! * @see org.xml.sax.ContentHandler#endPrefixMapping(java.lang.String) ! */ ! public void endPrefixMapping(String prefix) throws SAXException { ! throw new UnsupportedOperationException("This canonicalizer does not process namespaces."); ! } ! ! /* (non-Javadoc) ! * @see org.xml.sax.ContentHandler#skippedEntity(java.lang.String) ! */ ! public void skippedEntity(String name) throws SAXException { ! throw new UnsupportedOperationException("This canonicalizer does not process entities."); ! } ! ! /* (non-Javadoc) ! * @see org.xml.sax.ContentHandler#setDocumentLocator(org.xml.sax.Locator) ! */ ! public void setDocumentLocator(Locator locator) { ! // NO-OP ! } ! ! /* (non-Javadoc) ! * @see org.xml.sax.ContentHandler#processingInstruction(java.lang.String, java.lang.String) ! */ ! public void processingInstruction(String target, String data) ! throws SAXException { ! throw new UnsupportedOperationException("This canonicalizer does not process namespaces."); ! } ! ! /* (non-Javadoc) ! * @see org.xml.sax.ContentHandler#startPrefixMapping(java.lang.String, java.lang.String) ! */ ! public void startPrefixMapping(String prefix, String uri) ! throws SAXException { ! throw new UnsupportedOperationException("This canonicalizer does not process namespaces."); ! } ! ! /* (non-Javadoc) ! * @see org.xml.sax.ContentHandler#endElement(java.lang.String, java.lang.String, java.lang.String) ! */ ! public void endElement(String namespaceURI, String localName, String qName) ! throws SAXException { ! try { ! if (m_charBuf != null) { ! m_out.write(normalize(m_charBuf.toString())); ! } else { ! m_out.write(LF); ! } ! m_out.write(ETAGO); ! m_out.write(qName); ! m_out.write(ETAGC); ! m_charBuf = null; ! } catch (IOException ex) { ! throw new SAXException(ex); ! } ! } ! ! /* (non-Javadoc) ! * @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes) ! */ ! public void startElement( ! String namespaceURI, ! String localName, ! String qName, ! Attributes atts) ! throws SAXException { ! try { ! if (m_inDocument) m_out.write(LF); ! m_out.write(STAGO); ! m_out.write(normalize(qName)); ! if ((atts != null) && (atts.getLength() > 0)) { ! TreeSet ts = new TreeSet(); ! for (int i = 0; i < atts.getLength(); i++) { ! ts.add(atts.getQName(i)); ! } ! Iterator it = ts.iterator(); ! while (it.hasNext()) { ! String qname = (String)it.next(); ! m_out.write(' '); ! m_out.write(normalize(qname)); ! m_out.write("=\""); ! m_out.write(atts.getValue(qname)); ! m_out.write('"'); ! } ! } ! m_out.write(STAGC); ! m_inDocument = true; ! } catch (IOException ex) { ! throw new SAXException(ex); ! } ! } ! ! private String normalize(String str) { ! return str; ! } ! } |
From: Lars H. <lh...@us...> - 2005-07-08 16:27:32
|
Update of /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/impexp/cxtm/tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9420/src/org/tmapiutils/impexp/cxtm/tests Modified Files: CXTMTestCase.java CXTMTestSuite.java Log Message: Tabs -> Whitespaces Index: CXTMTestSuite.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/impexp/cxtm/tests/CXTMTestSuite.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** CXTMTestSuite.java 5 Mar 2005 17:30:09 -0000 1.2 --- CXTMTestSuite.java 8 Jul 2005 16:27:22 -0000 1.3 *************** *** 1,78 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * 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.tmapiutils.impexp.cxtm.tests; ! ! import java.io.File; ! import java.io.FileInputStream; ! import java.io.IOException; ! import java.util.Iterator; ! import java.util.Properties; ! ! import org.tmapiutils.impexp.cxtm.Canonicalize; ! import org.tmapiutils.impexp.cxtm.Driver; ! ! import junit.framework.Test; ! import junit.framework.TestSuite; ! ! /** ! * A JUnit TestSuite that is configured to run a series of ! * CXTMTestCase instances. The test suite is configured by ! * a Java properties file, the location of which is specified ! * by the value of the System property com.techquila.cxtm.test.files. ! */ ! public class CXTMTestSuite { ! ! public static Test suite() throws Exception { ! String driverClass = System.getProperty("org.tmapiutils.impexp.cxtm.Driver", "org.tmapiutils.impexp.cxtm.drivers.TM4JDriver"); ! Driver driver = (Driver) Class.forName(driverClass).newInstance(); ! driver.initialise(System.getProperties()); ! Canonicalize c = new Canonicalize(driver); ! String testFiles = System.getProperty("com.techquila.cxtm.test.files"); ! if (testFiles == null) { ! throw new RuntimeException("No test file list specified. Please set the system property com.techquila.cxtm.test.files to the location of the CXTM test file list."); ! } ! File f = new File(testFiles); ! TestSuite suite = new TestSuite("CXTMP Test Suite: " + f.getAbsolutePath()); ! if (!f.exists()) { ! throw new RuntimeException("Cannot locate test files list " + testFiles); ! } ! Properties testFileProps = new Properties(); ! try { ! testFileProps.load(new FileInputStream(f)); ! } catch (IOException ex) { ! throw new RuntimeException("The file " + f.getAbsolutePath() + " is not a valid properties file."); ! } ! ! String prefix = testFileProps.getProperty("uriprefix"); ! Boolean linefeeds = Boolean.valueOf(testFileProps.getProperty("insert.linefeeds")); ! c.setInsertLinefeeds(linefeeds.booleanValue()); ! ! Iterator it = testFileProps.keySet().iterator(); ! while (it.hasNext()) { ! String inFileName = (String) it.next(); ! if (inFileName.equals("uriprefix")) continue; ! if (inFileName.equals("insert.linefeeds")) continue; ! if (!inFileName.startsWith(";")) { ! String cxtmFileName = testFileProps.getProperty(inFileName); ! File inFile = new File(f.getParent(), inFileName); ! File outFile = new File(f.getParent(), cxtmFileName); ! suite.addTest(new CXTMTestCase(inFileName, c, inFile.getAbsolutePath(), prefix + inFileName, outFile.getAbsolutePath())); ! } ! } ! ! return suite; ! } ! } --- 1,78 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * 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.tmapiutils.impexp.cxtm.tests; ! ! import java.io.File; ! import java.io.FileInputStream; ! import java.io.IOException; ! import java.util.Iterator; ! import java.util.Properties; ! ! import org.tmapiutils.impexp.cxtm.Canonicalize; ! import org.tmapiutils.impexp.cxtm.Driver; ! ! import junit.framework.Test; ! import junit.framework.TestSuite; ! ! /** ! * A JUnit TestSuite that is configured to run a series of ! * CXTMTestCase instances. The test suite is configured by ! * a Java properties file, the location of which is specified ! * by the value of the System property com.techquila.cxtm.test.files. ! */ ! public class CXTMTestSuite { ! ! public static Test suite() throws Exception { ! String driverClass = System.getProperty("org.tmapiutils.impexp.cxtm.Driver", "org.tmapiutils.impexp.cxtm.drivers.TM4JDriver"); ! Driver driver = (Driver) Class.forName(driverClass).newInstance(); ! driver.initialise(System.getProperties()); ! Canonicalize c = new Canonicalize(driver); ! String testFiles = System.getProperty("com.techquila.cxtm.test.files"); ! if (testFiles == null) { ! throw new RuntimeException("No test file list specified. Please set the system property com.techquila.cxtm.test.files to the location of the CXTM test file list."); ! } ! File f = new File(testFiles); ! TestSuite suite = new TestSuite("CXTMP Test Suite: " + f.getAbsolutePath()); ! if (!f.exists()) { ! throw new RuntimeException("Cannot locate test files list " + testFiles); ! } ! Properties testFileProps = new Properties(); ! try { ! testFileProps.load(new FileInputStream(f)); ! } catch (IOException ex) { ! throw new RuntimeException("The file " + f.getAbsolutePath() + " is not a valid properties file."); ! } ! ! String prefix = testFileProps.getProperty("uriprefix"); ! Boolean linefeeds = Boolean.valueOf(testFileProps.getProperty("insert.linefeeds")); ! c.setInsertLinefeeds(linefeeds.booleanValue()); ! ! Iterator it = testFileProps.keySet().iterator(); ! while (it.hasNext()) { ! String inFileName = (String) it.next(); ! if (inFileName.equals("uriprefix")) continue; ! if (inFileName.equals("insert.linefeeds")) continue; ! if (!inFileName.startsWith(";")) { ! String cxtmFileName = testFileProps.getProperty(inFileName); ! File inFile = new File(f.getParent(), inFileName); ! File outFile = new File(f.getParent(), cxtmFileName); ! suite.addTest(new CXTMTestCase(inFileName, c, inFile.getAbsolutePath(), prefix + inFileName, outFile.getAbsolutePath())); ! } ! } ! ! return suite; ! } ! } Index: CXTMTestCase.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/impexp/cxtm/tests/CXTMTestCase.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** CXTMTestCase.java 5 Mar 2005 17:09:38 -0000 1.1 --- CXTMTestCase.java 8 Jul 2005 16:27:22 -0000 1.2 *************** *** 1,80 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * 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.tmapiutils.impexp.cxtm.tests; ! ! import java.io.ByteArrayOutputStream; ! import java.io.File; ! import java.io.FileInputStream; ! import java.io.InputStream; ! ! import junit.framework.TestCase; ! ! import org.tmapiutils.impexp.cxtm.Canonicalize; ! ! /** ! * A JUnit TestCase that loads an input topic map file, ! * generates the canonical form of the data model created ! * by the topic map processor and compares that against ! * an expected canonical form. If the generated canonical ! * form matches the expected form the test passes, otherwise ! * the test fails. ! */ ! public class CXTMTestCase extends TestCase { ! ! private String m_baseURI; ! ! private String m_cxtmFileName; ! ! private String m_xtmFileName; ! ! private Canonicalize m_canonicalizer; ! ! /** ! * Constructor for CXTMTestCase. ! */ ! public CXTMTestCase(String name, Canonicalize canonicalizer, String xtmFileName, String baseURI, String cxtmFileName) { ! super(name); ! m_canonicalizer = canonicalizer; ! m_xtmFileName = xtmFileName; ! m_cxtmFileName = cxtmFileName; ! m_baseURI = baseURI; ! } ! ! public static void main(String[] args) { ! junit.textui.TestRunner.run(CXTMTestCase.class); ! } ! ! public void runTest() throws Exception { ! File xtmFile = new File(m_xtmFileName); ! ByteArrayOutputStream expected = new ByteArrayOutputStream(); ! InputStream tmp = new FileInputStream(new File(m_cxtmFileName)); ! int b; ! while ((b = tmp.read()) != -1) { ! expected.write(b); ! } ! StringBuffer actual = new StringBuffer(); ! int mismatchAt = m_canonicalizer.canonicalize( ! new FileInputStream(xtmFile), ! m_baseURI, ! expected.toByteArray(), ! actual); ! assertTrue("Unexpected canonical form. Source file: " + m_xtmFileName + ".\n" + ! "\nExpected canonical form: " + expected.toString("UTF-8") + ! "\nProcessed canonical form: " + actual.toString(), ! mismatchAt < 0); ! } ! ! } --- 1,80 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed ! * ! * 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.tmapiutils.impexp.cxtm.tests; ! ! import java.io.ByteArrayOutputStream; ! import java.io.File; ! import java.io.FileInputStream; ! import java.io.InputStream; ! ! import junit.framework.TestCase; ! ! import org.tmapiutils.impexp.cxtm.Canonicalize; ! ! /** ! * A JUnit TestCase that loads an input topic map file, ! * generates the canonical form of the data model created ! * by the topic map processor and compares that against ! * an expected canonical form. If the generated canonical ! * form matches the expected form the test passes, otherwise ! * the test fails. ! */ ! public class CXTMTestCase extends TestCase { ! ! private String m_baseURI; ! ! private String m_cxtmFileName; ! ! private String m_xtmFileName; ! ! private Canonicalize m_canonicalizer; ! ! /** ! * Constructor for CXTMTestCase. ! */ ! public CXTMTestCase(String name, Canonicalize canonicalizer, String xtmFileName, String baseURI, String cxtmFileName) { ! super(name); ! m_canonicalizer = canonicalizer; ! m_xtmFileName = xtmFileName; ! m_cxtmFileName = cxtmFileName; ! m_baseURI = baseURI; ! } ! ! public static void main(String[] args) { ! junit.textui.TestRunner.run(CXTMTestCase.class); ! } ! ! public void runTest() throws Exception { ! File xtmFile = new File(m_xtmFileName); ! ByteArrayOutputStream expected = new ByteArrayOutputStream(); ! InputStream tmp = new FileInputStream(new File(m_cxtmFileName)); ! int b; ! while ((b = tmp.read()) != -1) { ! expected.write(b); ! } ! StringBuffer actual = new StringBuffer(); ! int mismatchAt = m_canonicalizer.canonicalize( ! new FileInputStream(xtmFile), ! m_baseURI, ! expected.toByteArray(), ! actual); ! assertTrue("Unexpected canonical form. Source file: " + m_xtmFileName + ".\n" + ! "\nExpected canonical form: " + expected.toString("UTF-8") + ! "\nProcessed canonical form: " + actual.toString(), ! mismatchAt < 0); ! } ! ! } |
From: Lars H. <lh...@us...> - 2005-07-08 16:27:32
|
Update of /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/impexp/cxtm/drivers In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9420/src/org/tmapiutils/impexp/cxtm/drivers Modified Files: TM4JDriver.java Log Message: Tabs -> Whitespaces Index: TM4JDriver.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/impexp/cxtm/drivers/TM4JDriver.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TM4JDriver.java 5 Mar 2005 17:09:38 -0000 1.1 --- TM4JDriver.java 8 Jul 2005 16:27:22 -0000 1.2 *************** *** 1,35 **** ! package com.techquila.cxtm.drivers; ! ! import java.io.InputStream; ! import java.util.Properties; ! ! import org.tm4j.tmapi.helpers.Wrapper; ! import org.tm4j.topicmap.TopicMapProvider; ! import org.tm4j.topicmap.source.SerializedTopicMapSource; ! import org.tmapi.core.TopicMap; ! ! import com.techquila.cxtm.Driver; ! ! /** ! * A CXTMP driver that interfaces to the TM4J topic map processor. ! */ ! public class TM4JDriver implements Driver { ! ! private TopicMapProvider m_provider; ! ! /* (non-Javadoc) ! * @see com.techquila.cxtm.Driver#importXTM(java.io.InputStream, java.lang.String) ! */ ! public TopicMap importXTM(InputStream src, String baseURI) throws Exception { ! SerializedTopicMapSource tmSrc = new SerializedTopicMapSource(src, m_provider.getLocatorFactory().createLocator("URI", baseURI)); ! return Wrapper.wrap(m_provider.addTopicMap(tmSrc)); ! } ! ! /* (non-Javadoc) ! * @see com.techquila.cxtm.Driver#initialise(java.util.Properties) ! */ ! public void initialise(Properties props) throws Exception { ! m_provider = org.tm4j.topicmap.TopicMapProviderFactory.newInstance().newTopicMapProvider(props); ! } ! ! } --- 1,35 ---- ! package com.techquila.cxtm.drivers; ! ! import java.io.InputStream; ! import java.util.Properties; ! ! import org.tm4j.tmapi.helpers.Wrapper; ! import org.tm4j.topicmap.TopicMapProvider; ! import org.tm4j.topicmap.source.SerializedTopicMapSource; ! import org.tmapi.core.TopicMap; ! ! import com.techquila.cxtm.Driver; ! ! /** ! * A CXTMP driver that interfaces to the TM4J topic map processor. ! */ ! public class TM4JDriver implements Driver { ! ! private TopicMapProvider m_provider; ! ! /* (non-Javadoc) ! * @see com.techquila.cxtm.Driver#importXTM(java.io.InputStream, java.lang.String) ! */ ! public TopicMap importXTM(InputStream src, String baseURI) throws Exception { ! SerializedTopicMapSource tmSrc = new SerializedTopicMapSource(src, m_provider.getLocatorFactory().createLocator("URI", baseURI)); ! return Wrapper.wrap(m_provider.addTopicMap(tmSrc)); ! } ! ! /* (non-Javadoc) ! * @see com.techquila.cxtm.Driver#initialise(java.util.Properties) ! */ ! public void initialise(Properties props) throws Exception { ! m_provider = org.tm4j.topicmap.TopicMapProviderFactory.newInstance().newTopicMapProvider(props); ! } ! ! } |
From: Lars H. <lh...@us...> - 2005-07-08 16:03:59
|
Update of /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30131/src/org/tmapiutils/query/tolog Modified Files: PreparedQuery.java QueryEvaluator.java QueryEvaluatorFactory.java TologFragmentBuilder.java TologFragmentBuilderException.java TologFragmentBuilderImpl.java TologParserException.java TologProcessingException.java TologResultsSet.java Log Message: Tabs -> Whitespaces Index: QueryEvaluator.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/QueryEvaluator.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** QueryEvaluator.java 8 Mar 2005 12:33:39 -0000 1.2 --- QueryEvaluator.java 8 Jul 2005 16:03:19 -0000 1.3 *************** *** 1,109 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog; ! ! import java.io.IOException; ! import java.io.InputStream; ! import java.util.Map; ! ! import org.tmapiutils.query.tolog.TologResultsSet; ! ! /** ! * This is the high-level interface to the tolog 1.0 ! * query engine. Using this interface you can initialise ! * the evaluator by loading one or more rules module files or ! * by adding rules as strings. ! * This class also supports the registration of extension ! * predicates. ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public interface QueryEvaluator ! { ! ! /** ! * Loads a rules module from the specified stream. ! * @param src the input stream to be parsed ! * @throws IOException if the module file could not be read. ! * @throws TologParserException if the module file could be ! * read but contained syntax errors. ! */ ! public void addRulesModule(InputStream src, String prefix) ! throws IOException, TologParserException; ! ! /** ! * Adds a new rule to the QueryEvaluator. ! * @param rule the rule string in tolog syntax ! * @throws TologParserException if there is a syntax error in the rule string. ! */ ! public void addRule(String rule) throws TologParserException; ! ! /** ! * Parses (and possibly optimizes) the specified tolog query string. ! * The return value is the parsed query which can then be executed ! * simply by calling {PreparedQuery#execute()}. ! * @param queryString the tolog query string to be parsed. ! * @return the PreparedQuery that represents the parsed, optimized tolog query. ! * @throws TologParserException if a syntax error or parse-time error is found in <code>queryString</code> ! * @throws TologProcessingException if an error occurs during optimisation of the query. ! */ ! public PreparedQuery prepareQuery(String queryString) throws TologParserException, TologProcessingException; ! ! /** ! * A convenience method that parses and optimizes the specified ! * tolog query and then executes it immediately. ! * @param queryString the tolog query string to be evaluated ! * @return the results of the query evaluation. ! * @throws TologParserException if a syntax error or parse-time error is found in <code>queryString</code> ! * @throws TologProcessingException if an error occurrs during the optimisation or evaluation of the query. ! */ ! public TologResultsSet execute(String queryString) throws TologParserException, TologProcessingException; ! ! /** ! * A convenience method that parses and optimizes the specified ! * tolog query and then executes it immediately. ! * @param queryString the tolog query string to be evaluated ! * @param queryParams the replacement values for % references in the query string ! * @return the results of the query evaluation. ! * @throws TologParserException if a syntax error or parse-time error is found in <code>queryString</code> ! * @throws TologProcessingException if an error occurrs during the optimisation or evaluation of the query. ! */ ! public TologResultsSet execute(String queryString, Object[] queryParams) throws TologParserException, TologProcessingException; ! ! /** ! * Registers an extension predicate with the QueryEvaluator. ! * All implementation classes MUST implement the {@link Predicate} interface. ! * If <code>predicateName</code> is the name of an already registered predicate, ! * then the new registration overwrites the old one. ! * @param predicateName the name to be used to reference the predicate from a tolog query. ! * @param predicateClass the implementation class for the predicate. ! * @throws IllegalArgumentException if the specified implementation class does not implement the Predicate interface. ! */ ! public void registerPredicateClass(String predicateName, Class predicateClass) ! throws IllegalArgumentException; ! ! /** ! * Returns a Map of the predicates currently registered with the ! * QueryEvaluator. The Map key is the name of the predicate and ! * the value is the implementation Class of the predicate. ! */ ! public Map getRegisteredPredicates(); ! ! } ! --- 1,109 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog; ! ! import java.io.IOException; ! import java.io.InputStream; ! import java.util.Map; ! ! import org.tmapiutils.query.tolog.TologResultsSet; ! ! /** ! * This is the high-level interface to the tolog 1.0 ! * query engine. Using this interface you can initialise ! * the evaluator by loading one or more rules module files or ! * by adding rules as strings. ! * This class also supports the registration of extension ! * predicates. ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public interface QueryEvaluator ! { ! ! /** ! * Loads a rules module from the specified stream. ! * @param src the input stream to be parsed ! * @throws IOException if the module file could not be read. ! * @throws TologParserException if the module file could be ! * read but contained syntax errors. ! */ ! public void addRulesModule(InputStream src, String prefix) ! throws IOException, TologParserException; ! ! /** ! * Adds a new rule to the QueryEvaluator. ! * @param rule the rule string in tolog syntax ! * @throws TologParserException if there is a syntax error in the rule string. ! */ ! public void addRule(String rule) throws TologParserException; ! ! /** ! * Parses (and possibly optimizes) the specified tolog query string. ! * The return value is the parsed query which can then be executed ! * simply by calling {PreparedQuery#execute()}. ! * @param queryString the tolog query string to be parsed. ! * @return the PreparedQuery that represents the parsed, optimized tolog query. ! * @throws TologParserException if a syntax error or parse-time error is found in <code>queryString</code> ! * @throws TologProcessingException if an error occurs during optimisation of the query. ! */ ! public PreparedQuery prepareQuery(String queryString) throws TologParserException, TologProcessingException; ! ! /** ! * A convenience method that parses and optimizes the specified ! * tolog query and then executes it immediately. ! * @param queryString the tolog query string to be evaluated ! * @return the results of the query evaluation. ! * @throws TologParserException if a syntax error or parse-time error is found in <code>queryString</code> ! * @throws TologProcessingException if an error occurrs during the optimisation or evaluation of the query. ! */ ! public TologResultsSet execute(String queryString) throws TologParserException, TologProcessingException; ! ! /** ! * A convenience method that parses and optimizes the specified ! * tolog query and then executes it immediately. ! * @param queryString the tolog query string to be evaluated ! * @param queryParams the replacement values for % references in the query string ! * @return the results of the query evaluation. ! * @throws TologParserException if a syntax error or parse-time error is found in <code>queryString</code> ! * @throws TologProcessingException if an error occurrs during the optimisation or evaluation of the query. ! */ ! public TologResultsSet execute(String queryString, Object[] queryParams) throws TologParserException, TologProcessingException; ! ! /** ! * Registers an extension predicate with the QueryEvaluator. ! * All implementation classes MUST implement the {@link Predicate} interface. ! * If <code>predicateName</code> is the name of an already registered predicate, ! * then the new registration overwrites the old one. ! * @param predicateName the name to be used to reference the predicate from a tolog query. ! * @param predicateClass the implementation class for the predicate. ! * @throws IllegalArgumentException if the specified implementation class does not implement the Predicate interface. ! */ ! public void registerPredicateClass(String predicateName, Class predicateClass) ! throws IllegalArgumentException; ! ! /** ! * Returns a Map of the predicates currently registered with the ! * QueryEvaluator. The Map key is the name of the predicate and ! * the value is the implementation Class of the predicate. ! */ ! public Map getRegisteredPredicates(); ! ! } ! Index: QueryEvaluatorFactory.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/QueryEvaluatorFactory.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** QueryEvaluatorFactory.java 8 Mar 2005 12:33:39 -0000 1.2 --- QueryEvaluatorFactory.java 8 Jul 2005 16:03:19 -0000 1.3 *************** *** 1,36 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog; ! ! import org.tmapiutils.query.tolog.memory.QueryEvaluatorImpl; ! import org.tmapi.core.TopicMap; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class QueryEvaluatorFactory ! { ! ! public static QueryEvaluator newQueryEvaluator(TopicMap tm) { ! QueryEvaluator qe = new QueryEvaluatorImpl(tm); ! return qe; ! } ! } ! --- 1,36 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog; ! ! import org.tmapiutils.query.tolog.memory.QueryEvaluatorImpl; ! import org.tmapi.core.TopicMap; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class QueryEvaluatorFactory ! { ! ! public static QueryEvaluator newQueryEvaluator(TopicMap tm) { ! QueryEvaluator qe = new QueryEvaluatorImpl(tm); ! return qe; ! } ! } ! Index: TologParserException.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/TologParserException.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TologParserException.java 8 Mar 2005 12:33:39 -0000 1.2 --- TologParserException.java 8 Jul 2005 16:03:19 -0000 1.3 *************** *** 1,35 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class TologParserException extends Exception { ! ! public TologParserException(String msg) { ! super(msg); ! } ! ! public TologParserException(String msg, Throwable cause) { ! super(msg, cause); ! } ! } ! --- 1,35 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class TologParserException extends Exception { ! ! public TologParserException(String msg) { ! super(msg); ! } ! ! public TologParserException(String msg, Throwable cause) { ! super(msg, cause); ! } ! } ! Index: TologProcessingException.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/TologProcessingException.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TologProcessingException.java 8 Mar 2005 12:33:39 -0000 1.2 --- TologProcessingException.java 8 Jul 2005 16:03:19 -0000 1.3 *************** *** 1,35 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class TologProcessingException extends Exception { ! ! public TologProcessingException(String msg) { ! super(msg); ! } ! ! public TologProcessingException(String msg, Throwable cause) { ! super(msg, cause); ! } ! } ! --- 1,35 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class TologProcessingException extends Exception { ! ! public TologProcessingException(String msg) { ! super(msg); ! } ! ! public TologProcessingException(String msg, Throwable cause) { ! super(msg, cause); ! } ! } ! Index: TologFragmentBuilderException.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/TologFragmentBuilderException.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TologFragmentBuilderException.java 8 Mar 2005 12:33:39 -0000 1.2 --- TologFragmentBuilderException.java 8 Jul 2005 16:03:19 -0000 1.3 *************** *** 1,61 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog; ! ! ! /** ! * Exception raised by the TologFragmentBuilder interface when exporting ! * a TologResultsSet object into a topic map fragment. ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class TologFragmentBuilderException extends Exception { ! private Throwable m_cause; ! ! /** ! * Create a new TologFragmentBuilderException with the specified message. ! */ ! public TologFragmentBuilderException(String msg) { ! super(msg); ! } ! ! /** ! * Create a new TologFragmentBuilderException with the specified message and ! * nested cause. ! */ ! public TologFragmentBuilderException(String msg, Throwable cause) { ! super(msg + "Cause:\n" + cause.getMessage()); ! m_cause = cause; ! } ! ! public Throwable getCause() { ! return m_cause; ! } ! ! public String toString() { ! String ret = super.toString(); ! ! if (m_cause != null) { ! ret = ret + "\nCause:\n" + m_cause.toString(); ! } ! ! return ret; ! } ! } ! --- 1,61 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog; ! ! ! /** ! * Exception raised by the TologFragmentBuilder interface when exporting ! * a TologResultsSet object into a topic map fragment. ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class TologFragmentBuilderException extends Exception { ! private Throwable m_cause; ! ! /** ! * Create a new TologFragmentBuilderException with the specified message. ! */ ! public TologFragmentBuilderException(String msg) { ! super(msg); ! } ! ! /** ! * Create a new TologFragmentBuilderException with the specified message and ! * nested cause. ! */ ! public TologFragmentBuilderException(String msg, Throwable cause) { ! super(msg + "Cause:\n" + cause.getMessage()); ! m_cause = cause; ! } ! ! public Throwable getCause() { ! return m_cause; ! } ! ! public String toString() { ! String ret = super.toString(); ! ! if (m_cause != null) { ! ret = ret + "\nCause:\n" + m_cause.toString(); ! } ! ! return ret; ! } ! } ! Index: TologFragmentBuilderImpl.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/TologFragmentBuilderImpl.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** TologFragmentBuilderImpl.java 8 Mar 2005 12:33:39 -0000 1.3 --- TologFragmentBuilderImpl.java 8 Jul 2005 16:03:19 -0000 1.4 *************** *** 1,232 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog; ! ! import org.tmapi.core.Locator; ! import org.tmapi.core.LocatorFactory; ! import org.tmapi.core.LocatorFactoryException; ! // TMAPI ! import org.tmapi.core.Association; ! import org.tmapi.core.TopicName; ! import org.tmapi.core.AssociationRole; ! import org.tmapi.core.Topic; ! import org.tmapi.core.TopicMap; ! import org.tmapi.core.TopicMapFactory; ! import org.tmapi.core.TopicMapProcessingException; ! import org.tmapi.core.utils.IDGenerator; ! import org.tmapi.core.utils.IDGeneratorFactory; ! import org.tmapi.core.utils.TopicMapFragment; ! ! import java.beans.PropertyVetoException; ! ! import java.util.ArrayList; ! import java.util.List; ! ! ! /** ! * Default implementation of the TologFragmentBuilder interface. ! */ ! public class TologFragmentBuilderImpl implements TologFragmentBuilder { ! public static final String DEFAULT_VARTOPIC_SUBJECT_INDICATOR_PREFIX = "http://tm4j.org/tolog/variable/"; ! public static final String ROW_ASSOC_TYPE_SUBJECT_INDICATOR = "http://tm4j.org/tolog/result-set-row"; ! TopicMapFragment m_frag = null; ! boolean m_convertRowInfo = false; ! boolean m_genVarTopicSI = true; ! String m_varTopicSIPrefix = DEFAULT_VARTOPIC_SUBJECT_INDICATOR_PREFIX; ! boolean m_genVarTopicName = true; ! String m_varTopicNamePrefix = ""; ! String m_rowAssocTypeName = null; ! IDGenerator m_idgen = IDGeneratorFactory.newIDGenerator(); ! List m_rowVariableTopics; ! Topic m_rowAssocType; ! ! public TologFragmentBuilderImpl() { ! } ! ! public TologFragmentBuilderImpl(TopicMapFragment tmFrag) { ! m_frag = tmFrag; ! } ! ! public TologFragmentBuilderImpl(TopicMapFragment tmFrag, ! boolean convertRowInfo) { ! m_frag = tmFrag; ! m_convertRowInfo = convertRowInfo; ! } ! ! public void setFragment(TopicMapFragment tmFrag) { ! m_frag = tmFrag; ! } ! ! public void setConvertRowInformation(boolean convertRowInfo) { ! m_convertRowInfo = convertRowInfo; ! } ! ! public void setGenerateVarTopicSubjectIndicators(boolean genVarTopicSI) { ! m_genVarTopicSI = genVarTopicSI; ! } ! ! public void setVarTopicSubjectIndicatorPrefix(String vtPrefix) { ! m_varTopicSIPrefix = vtPrefix; ! } ! ! public void setGenerateVarTopicNames(boolean genVarTopicNames) { ! m_genVarTopicName = genVarTopicNames; ! } ! ! public void setVarTopicNamePrefix(String namePrefix) { ! m_varTopicNamePrefix = namePrefix; ! } ! ! public void setRowAssociationTypeName(String rowAssocTypeName) { ! m_rowAssocTypeName = rowAssocTypeName; ! } ! ! public void exportResultsSet(TologResultsSet rs) ! throws TologFragmentBuilderException { ! if (m_convertRowInfo) { ! createRowAssocType(); ! createRowVariableTopics(rs); ! } ! ! for (int i = 0; i < rs.getNumRows(); i++) { ! List copiedRow = copyRow(rs.getRow(i)); ! ! if (m_convertRowInfo) { ! createRowAssoc(copiedRow); ! } ! } ! } ! ! public void createRowAssocType() throws TologFragmentBuilderException { ! TopicMapFactory factory = m_frag.getTopicMap().getFactory(); ! LocatorFactory locFactory = m_frag.getTopicMap().getLocatorFactory(); ! ! try { ! Locator ratLoc = locFactory.createLocator("URI", ! ROW_ASSOC_TYPE_SUBJECT_INDICATOR); ! m_rowAssocType = m_frag.getTopicMap().createTopic(m_idgen.getObjectId()); ! m_rowAssocType.addSubjectIdentifier(ratLoc); ! ! if (m_rowAssocTypeName != null) { ! TopicName bn = m_rowAssocType.createName(null); ! bn.setValue(m_rowAssocTypeName); ! } ! } catch (LocatorFactoryException ex) { ! throw new TologFragmentBuilderException("Error in creating subject indicator for row association type.", ! ex); ! } catch (TopicMapProcessingException ex) { ! throw new TologFragmentBuilderException("Error creating row association type topic.", ! ex); ! } catch (PropertyVetoException ex) { ! throw new TologFragmentBuilderException("Unable to fully initialise row association type topic.", ! ex); ! } ! } ! ! public void createRowVariableTopics(TologResultsSet rs) ! throws TologFragmentBuilderException { ! TopicMap fragTM = m_frag.getTopicMap(); ! LocatorFactory locFactory = fragTM.getLocatorFactory(); ! ! try { ! m_rowVariableTopics = new ArrayList(); ! ! for (int i = 0; i < rs.getNumCols(); i++) { ! String colName = rs.getVar(i); ! Topic t = fragTM.createTopic(m_idgen.getObjectId()); ! ! if (m_genVarTopicSI) { ! Locator l = locFactory.createLocator("URI", ! m_varTopicSIPrefix + colName); ! t.addSubjectIdentifier(l); ! } ! ! if (m_genVarTopicName) { ! String name = m_varTopicNamePrefix + colName; ! TopicName bn = t.createName(null); ! bn.setValue(name); ! } ! ! m_rowVariableTopics.add(t); ! } ! } catch (TopicMapProcessingException ex) { ! throw new TologFragmentBuilderException("Could not construct row variable topic.", ! ex); ! } catch (LocatorFactoryException ex) { ! throw new TologFragmentBuilderException("Error creating subject indicator for row variable topic.", ! ex); ! } catch (PropertyVetoException ex) { ! throw new TologFragmentBuilderException("Creation of row variable topic was vetoed.", ! ex); ! } ! } ! ! public List copyRow(List row) throws TologFragmentBuilderException { ! List copiedRow = new ArrayList(); ! ! try { ! for (int i = 0; i < row.size(); i++) { ! if (row.get(i) instanceof Topic) { ! Topic src = (Topic) row.get(i); ! ! if (m_frag.getTopicMap().getObjectById(src.getObjectId()) == null) { ! Topic cp = m_frag.addTopic((Topic) row.get(i), 0); ! copiedRow.add(cp); ! } else { ! copiedRow.add((Topic) m_frag.getTopicMap() ! .getObjectById(src.getObjectId())); ! } ! } else { ! copiedRow.add(null); ! } ! } ! } catch (LocatorFactoryException ex) { ! throw new TologFragmentBuilderException("Error while copying result topic.", ! ex); ! } catch (TopicMapProcessingException ex) { ! throw new TologFragmentBuilderException("Error while copying result topic.", ! ex); ! } ! ! return copiedRow; ! } ! ! public void createRowAssoc(List row) throws TologFragmentBuilderException { ! TopicMap fragTM = m_frag.getTopicMap(); ! ! try { ! Association assoc = fragTM.createAssociation(null); ! ! for (int i = 0; i < row.size(); i++) { ! if (row.get(i) != null) { ! AssociationRole m = assoc.createAssociationRole(null); ! m.setType((Topic) m_rowVariableTopics.get(i)); ! m.addPlayer((Topic) row.get(i)); ! } ! } ! ! assoc.setType(m_rowAssocType); ! } catch (TopicMapProcessingException ex) { ! throw new TologFragmentBuilderException("Error while creating row association.", ! ex); ! } catch (PropertyVetoException ex) { ! throw new TologFragmentBuilderException("Creation of row association was vetoed.", ! ex); ! } ! } ! } --- 1,232 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog; ! ! import org.tmapi.core.Locator; ! import org.tmapi.core.LocatorFactory; ! import org.tmapi.core.LocatorFactoryException; ! // TMAPI ! import org.tmapi.core.Association; ! import org.tmapi.core.TopicName; ! import org.tmapi.core.AssociationRole; ! import org.tmapi.core.Topic; ! import org.tmapi.core.TopicMap; ! import org.tmapi.core.TopicMapFactory; ! import org.tmapi.core.TopicMapProcessingException; ! import org.tmapi.core.utils.IDGenerator; ! import org.tmapi.core.utils.IDGeneratorFactory; ! import org.tmapi.core.utils.TopicMapFragment; ! ! import java.beans.PropertyVetoException; ! ! import java.util.ArrayList; ! import java.util.List; ! ! ! /** ! * Default implementation of the TologFragmentBuilder interface. ! */ ! public class TologFragmentBuilderImpl implements TologFragmentBuilder { ! public static final String DEFAULT_VARTOPIC_SUBJECT_INDICATOR_PREFIX = "http://tm4j.org/tolog/variable/"; ! public static final String ROW_ASSOC_TYPE_SUBJECT_INDICATOR = "http://tm4j.org/tolog/result-set-row"; ! TopicMapFragment m_frag = null; ! boolean m_convertRowInfo = false; ! boolean m_genVarTopicSI = true; ! String m_varTopicSIPrefix = DEFAULT_VARTOPIC_SUBJECT_INDICATOR_PREFIX; ! boolean m_genVarTopicName = true; ! String m_varTopicNamePrefix = ""; ! String m_rowAssocTypeName = null; ! IDGenerator m_idgen = IDGeneratorFactory.newIDGenerator(); ! List m_rowVariableTopics; ! Topic m_rowAssocType; ! ! public TologFragmentBuilderImpl() { ! } ! ! public TologFragmentBuilderImpl(TopicMapFragment tmFrag) { ! m_frag = tmFrag; ! } ! ! public TologFragmentBuilderImpl(TopicMapFragment tmFrag, ! boolean convertRowInfo) { ! m_frag = tmFrag; ! m_convertRowInfo = convertRowInfo; ! } ! ! public void setFragment(TopicMapFragment tmFrag) { ! m_frag = tmFrag; ! } ! ! public void setConvertRowInformation(boolean convertRowInfo) { ! m_convertRowInfo = convertRowInfo; ! } ! ! public void setGenerateVarTopicSubjectIndicators(boolean genVarTopicSI) { ! m_genVarTopicSI = genVarTopicSI; ! } ! ! public void setVarTopicSubjectIndicatorPrefix(String vtPrefix) { ! m_varTopicSIPrefix = vtPrefix; ! } ! ! public void setGenerateVarTopicNames(boolean genVarTopicNames) { ! m_genVarTopicName = genVarTopicNames; ! } ! ! public void setVarTopicNamePrefix(String namePrefix) { ! m_varTopicNamePrefix = namePrefix; ! } ! ! public void setRowAssociationTypeName(String rowAssocTypeName) { ! m_rowAssocTypeName = rowAssocTypeName; ! } ! ! public void exportResultsSet(TologResultsSet rs) ! throws TologFragmentBuilderException { ! if (m_convertRowInfo) { ! createRowAssocType(); ! createRowVariableTopics(rs); ! } ! ! for (int i = 0; i < rs.getNumRows(); i++) { ! List copiedRow = copyRow(rs.getRow(i)); ! ! if (m_convertRowInfo) { ! createRowAssoc(copiedRow); ! } ! } ! } ! ! public void createRowAssocType() throws TologFragmentBuilderException { ! TopicMapFactory factory = m_frag.getTopicMap().getFactory(); ! LocatorFactory locFactory = m_frag.getTopicMap().getLocatorFactory(); ! ! try { ! Locator ratLoc = locFactory.createLocator("URI", ! ROW_ASSOC_TYPE_SUBJECT_INDICATOR); ! m_rowAssocType = m_frag.getTopicMap().createTopic(m_idgen.getObjectId()); ! m_rowAssocType.addSubjectIdentifier(ratLoc); ! ! if (m_rowAssocTypeName != null) { ! TopicName bn = m_rowAssocType.createName(null); ! bn.setValue(m_rowAssocTypeName); ! } ! } catch (LocatorFactoryException ex) { ! throw new TologFragmentBuilderException("Error in creating subject indicator for row association type.", ! ex); ! } catch (TopicMapProcessingException ex) { ! throw new TologFragmentBuilderException("Error creating row association type topic.", ! ex); ! } catch (PropertyVetoException ex) { ! throw new TologFragmentBuilderException("Unable to fully initialise row association type topic.", ! ex); ! } ! } ! ! public void createRowVariableTopics(TologResultsSet rs) ! throws TologFragmentBuilderException { ! TopicMap fragTM = m_frag.getTopicMap(); ! LocatorFactory locFactory = fragTM.getLocatorFactory(); ! ! try { ! m_rowVariableTopics = new ArrayList(); ! ! for (int i = 0; i < rs.getNumCols(); i++) { ! String colName = rs.getVar(i); ! Topic t = fragTM.createTopic(m_idgen.getObjectId()); ! ! if (m_genVarTopicSI) { ! Locator l = locFactory.createLocator("URI", ! m_varTopicSIPrefix + colName); ! t.addSubjectIdentifier(l); ! } ! ! if (m_genVarTopicName) { ! String name = m_varTopicNamePrefix + colName; ! TopicName bn = t.createName(null); ! bn.setValue(name); ! } ! ! m_rowVariableTopics.add(t); ! } ! } catch (TopicMapProcessingException ex) { ! throw new TologFragmentBuilderException("Could not construct row variable topic.", ! ex); ! } catch (LocatorFactoryException ex) { ! throw new TologFragmentBuilderException("Error creating subject indicator for row variable topic.", ! ex); ! } catch (PropertyVetoException ex) { ! throw new TologFragmentBuilderException("Creation of row variable topic was vetoed.", ! ex); ! } ! } ! ! public List copyRow(List row) throws TologFragmentBuilderException { ! List copiedRow = new ArrayList(); ! ! try { ! for (int i = 0; i < row.size(); i++) { ! if (row.get(i) instanceof Topic) { ! Topic src = (Topic) row.get(i); ! ! if (m_frag.getTopicMap().getObjectById(src.getObjectId()) == null) { ! Topic cp = m_frag.addTopic((Topic) row.get(i), 0); ! copiedRow.add(cp); ! } else { ! copiedRow.add((Topic) m_frag.getTopicMap() ! .getObjectById(src.getObjectId())); ! } ! } else { ! copiedRow.add(null); ! } ! } ! } catch (LocatorFactoryException ex) { ! throw new TologFragmentBuilderException("Error while copying result topic.", ! ex); ! } catch (TopicMapProcessingException ex) { ! throw new TologFragmentBuilderException("Error while copying result topic.", ! ex); ! } ! ! return copiedRow; ! } ! ! public void createRowAssoc(List row) throws TologFragmentBuilderException { ! TopicMap fragTM = m_frag.getTopicMap(); ! ! try { ! Association assoc = fragTM.createAssociation(null); ! ! for (int i = 0; i < row.size(); i++) { ! if (row.get(i) != null) { ! AssociationRole m = assoc.createAssociationRole(null); ! m.setType((Topic) m_rowVariableTopics.get(i)); ! m.addPlayer((Topic) row.get(i)); ! } ! } ! ! assoc.setType(m_rowAssocType); ! } catch (TopicMapProcessingException ex) { ! throw new TologFragmentBuilderException("Error while creating row association.", ! ex); ! } catch (PropertyVetoException ex) { ! throw new TologFragmentBuilderException("Creation of row association was vetoed.", ! ex); ! } ! } ! } Index: TologResultsSet.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/TologResultsSet.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TologResultsSet.java 8 Mar 2005 12:33:39 -0000 1.2 --- TologResultsSet.java 8 Jul 2005 16:03:19 -0000 1.3 *************** *** 1,59 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog; ! ! import java.util.List; ! ! ! /** ! * This interface represents a collection of results from a single Tolog ! * query. The collection is somewhat similar to a JDBC results set and can ! * be thought of as a table consisting of a number of named columns with ! * one row for each distinct match to the Tolog query. ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public interface TologResultsSet { ! /** ! * Returns the number of distinct matches in this results set. ! * (i.e. the number of "rows" in the set). ! */ ! public int getNumRows(); ! ! /** ! * Returns the number of variables listed in each match in this results set. ! * (i.e. the number of "columns" in the set). ! */ ! public int getNumCols(); ! ! /** ! * Returns the name of the variable in the <code>colNum</code>'th position ! * of the results set match. (equivalent to the column name in a JDBC query). ! * The index starts at 0. ! */ ! public String getVar(int colNum); ! ! /** ! * Returns a single match from the results set. The index starts at 0. ! * The row is returned at a list containing the results in colum order. ! * Each list entry is a ({@link org.tmapi.core.Topic} object. ! */ ! public List getRow(int rowNum); ! } ! --- 1,59 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog; ! ! import java.util.List; ! ! ! /** ! * This interface represents a collection of results from a single Tolog ! * query. The collection is somewhat similar to a JDBC results set and can ! * be thought of as a table consisting of a number of named columns with ! * one row for each distinct match to the Tolog query. ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public interface TologResultsSet { ! /** ! * Returns the number of distinct matches in this results set. ! * (i.e. the number of "rows" in the set). ! */ ! public int getNumRows(); ! ! /** ! * Returns the number of variables listed in each match in this results set. ! * (i.e. the number of "columns" in the set). ! */ ! public int getNumCols(); ! ! /** ! * Returns the name of the variable in the <code>colNum</code>'th position ! * of the results set match. (equivalent to the column name in a JDBC query). ! * The index starts at 0. ! */ ! public String getVar(int colNum); ! ! /** ! * Returns a single match from the results set. The index starts at 0. ! * The row is returned at a list containing the results in colum order. ! * Each list entry is a ({@link org.tmapi.core.Topic} object. ! */ ! public List getRow(int rowNum); ! } ! Index: PreparedQuery.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/PreparedQuery.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PreparedQuery.java 8 Mar 2005 12:33:39 -0000 1.2 --- PreparedQuery.java 8 Jul 2005 16:03:19 -0000 1.3 *************** *** 1,55 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog; ! ! import org.tmapiutils.query.tolog.TologResultsSet; ! ! /** ! * Represents a parsed, optimized tolog query which can ! * be executed as often as required. ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public interface PreparedQuery ! { ! /** ! * Returns the prepared query string in tolog syntax. ! * This string may differ from the original string used to ! * prepare the query, as optimisations may have been performed ! * by the QueryEvaluator. ! * @return the prepared query string in tolog syntax. ! */ ! public String getQueryString(); ! ! /** ! * Executes the prepared query. ! * @return the results of the query evaluation. ! * @throws TologProcessingException if an error occurred during query evaluation. ! */ ! public TologResultsSet execute() throws TologProcessingException; ! ! /** ! * Executes a prepared query substituting <i>%n</i> references with the <i>n</i>th value from ! * the parameter array. ! * @param params the parameter array for this query evaluation ! * @return the results of the query evaluation. ! * @throws TologProcessingException if an error occurred during query evaluation. ! */ ! public TologResultsSet execute(Object[] params) throws TologProcessingException; ! } --- 1,55 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog; ! ! import org.tmapiutils.query.tolog.TologResultsSet; ! ! /** ! * Represents a parsed, optimized tolog query which can ! * be executed as often as required. ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public interface PreparedQuery ! { ! /** ! * Returns the prepared query string in tolog syntax. ! * This string may differ from the original string used to ! * prepare the query, as optimisations may have been performed ! * by the QueryEvaluator. ! * @return the prepared query string in tolog syntax. ! */ ! public String getQueryString(); ! ! /** ! * Executes the prepared query. ! * @return the results of the query evaluation. ! * @throws TologProcessingException if an error occurred during query evaluation. ! */ ! public TologResultsSet execute() throws TologProcessingException; ! ! /** ! * Executes a prepared query substituting <i>%n</i> references with the <i>n</i>th value from ! * the parameter array. ! * @param params the parameter array for this query evaluation ! * @return the results of the query evaluation. ! * @throws TologProcessingException if an error occurred during query evaluation. ! */ ! public TologResultsSet execute(Object[] params) throws TologProcessingException; ! } Index: TologFragmentBuilder.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/TologFragmentBuilder.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TologFragmentBuilder.java 8 Mar 2005 12:33:39 -0000 1.2 --- TologFragmentBuilder.java 8 Jul 2005 16:03:19 -0000 1.3 *************** *** 1,101 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog; ! ! import org.tmapi.core.utils.TopicMapFragment; ! ! ! /** ! * The interface for implementations which export a TologResultsSet into ! * a TopicMapFragment. ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public interface TologFragmentBuilder { ! /** ! * Set the TopicMapFragment into which the results set should be exported. ! * @param fragment the topic map fragment to export to. ! */ ! public void setFragment(TopicMapFragment fragment); ! ! /** ! * Set the flag which indicates whether or not row information should be exported. ! * If <code>true</code> then the exported topic map fragment will contain ! * one association for each row in the TologResultsSet. Each association ! * will have one member for each column in the results set with a single ! * player for that member. ! */ ! public void setConvertRowInformation(boolean convertRowInfo); ! ! /** ! * Set the flag which indicates whether or not topics representing the ! * results set variables should be given subject indicators. ! * @param genVarTopicSI true if the topics representing results set variables ! * should be given subject indicators, false otherwise. ! */ ! public void setGenerateVarTopicSubjectIndicators(boolean genVarTopicSI); ! ! /** ! * Sets the prefix part of the subject indicator locator address to be ! * generated for results set variables. The final form of the locator ! * addresses generated will be {vtPrefix}{variablename}. It is the responsibility ! * of the caller to ensure that the prefix is such that these generated addresses ! * are valid URI strings. ! * @param vtPrefix the prefix string to be used for generating the subject ! * indicator locators for the topics representing results set ! * variables. ! */ ! public void setVarTopicSubjectIndicatorPrefix(String vtPrefix); ! ! /** ! * Set the flag which indicates whether or not topics representing the ! * results set variables should be given base names. ! * @param genVarTopicNames true if the topics representing results set variables ! * should be given base names, false otherwise. ! */ ! public void setGenerateVarTopicNames(boolean genVarTopicNames); ! ! /** ! * Sets the string to be prepended to the base name string generated for ! * topics which represent results set variables. The final form of the ! * generated names will be {namePrefix}{variable name}. ! * @param namePrefix the prefix string used in generating names for the ! * topics which represent results set variables. ! */ ! public void setVarTopicNamePrefix(String namePrefix); ! ! /** ! * Sets the base name string to be assigned to the topic which ! * types the row associations generated if the convertRowInformation option ! * is set to <code>true</code>. ! * @param rowAssocTypeName the name assigned to the topic which is used to ! * type associations generated for each row in the ! * results set. ! */ ! public void setRowAssociationTypeName(String rowAssocTypeName); ! ! /** ! * Perform the export with the currently specified export ! * parameters. This method will fail if setFragment() has not been ! * called before calling this method. ! * @param rs the tolog results set to be exported. ! */ ! public void exportResultsSet(TologResultsSet rs) ! throws TologFragmentBuilderException; ! } --- 1,101 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog; ! ! import org.tmapi.core.utils.TopicMapFragment; ! ! ! /** ! * The interface for implementations which export a TologResultsSet into ! * a TopicMapFragment. ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public interface TologFragmentBuilder { ! /** ! * Set the TopicMapFragment into which the results set should be exported. ! * @param fragment the topic map fragment to export to. ! */ ! public void setFragment(TopicMapFragment fragment); ! ! /** ! * Set the flag which indicates whether or not row information should be exported. ! * If <code>true</code> then the exported topic map fragment will contain ! * one association for each row in the TologResultsSet. Each association ! * will have one member for each column in the results set with a single ! * player for that member. ! */ ! public void setConvertRowInformation(boolean convertRowInfo); ! ! /** ! * Set the flag which indicates whether or not topics representing the ! * results set variables should be given subject indicators. ! * @param genVarTopicSI true if the topics representing results set variables ! * should be given subject indicators, false otherwise. ! */ ! public void setGenerateVarTopicSubjectIndicators(boolean genVarTopicSI); ! ! /** ! * Sets the prefix part of the subject indicator locator address to be ! * generated for results set variables. The final form of the locator ! * addresses generated will be {vtPrefix}{variablename}. It is the responsibility ! * of the caller to ensure that the prefix is such that these generated addresses ! * are valid URI strings. ! * @param vtPrefix the prefix string to be used for generating the subject ! * indicator locators for the topics representing results set ! * variables. ! */ ! public void setVarTopicSubjectIndicatorPrefix(String vtPrefix); ! ! /** ! * Set the flag which indicates whether or not topics representing the ! * results set variables should be given base names. ! * @param genVarTopicNames true if the topics representing results set variables ! * should be given base names, false otherwise. ! */ ! public void setGenerateVarTopicNames(boolean genVarTopicNames); ! ! /** ! * Sets the string to be prepended to the base name string generated for ! * topics which represent results set variables. The final form of the ! * generated names will be {namePrefix}{variable name}. ! * @param namePrefix the prefix string used in generating names for the ! * topics which represent results set variables. ! */ ! public void setVarTopicNamePrefix(String namePrefix); ! ! /** ! * Sets the base name string to be assigned to the topic which ! * types the row associations generated if the convertRowInformation option ! * is set to <code>true</code>. ! * @param rowAssocTypeName the name assigned to the topic which is used to ! * type associations generated for each row in the ! * results set. ! */ ! public void setRowAssociationTypeName(String rowAssocTypeName); ! ! /** ! * Perform the export with the currently specified export ! * parameters. This method will fail if setFragment() has not been ! * called before calling this method. ! * @param rs the tolog results set to be exported. ! */ ! public void exportResultsSet(TologResultsSet rs) ! throws TologFragmentBuilderException; ! } |
From: Lars H. <lh...@us...> - 2005-07-08 16:03:58
|
Update of /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/memory In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30131/src/org/tmapiutils/query/tolog/memory Modified Files: PreparedQueryImpl.java QueryEvaluatorImpl.java Log Message: Tabs -> Whitespaces Index: PreparedQueryImpl.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/memory/PreparedQueryImpl.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PreparedQueryImpl.java 8 Mar 2005 12:33:40 -0000 1.2 --- PreparedQueryImpl.java 8 Jul 2005 16:03:19 -0000 1.3 *************** *** 1,67 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.memory; ! ! import org.tmapiutils.query.tolog.TologResultsSet; ! import org.tmapiutils.query.tolog.PreparedQuery; ! import org.tmapiutils.query.tolog.TologProcessingException; ! import org.tmapiutils.query.tolog.parser.TologQuery; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class PreparedQueryImpl implements PreparedQuery { ! ! private TologQuery m_query; ! ! public PreparedQueryImpl(TologQuery q) { ! m_query = q; ! rewrite(); ! } ! ! /** ! * Rewrite the query for optimisation purposes ! */ ! private void rewrite() { ! // TODO Implement query rewriting optimisation strategy. ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.PreparedQuery#getQueryString() ! */ ! public String getQueryString() { ! return m_query.toString(); ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.PreparedQuery#execute() ! */ ! public TologResultsSet execute() throws TologProcessingException { ! return m_query.execute(); ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.PreparedQuery#execute(java.lang.Object[]) ! */ ! public TologResultsSet execute(Object[] params) throws TologProcessingException { ! return m_query.execute(params); ! } ! ! } --- 1,67 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.memory; ! ! import org.tmapiutils.query.tolog.TologResultsSet; ! import org.tmapiutils.query.tolog.PreparedQuery; ! import org.tmapiutils.query.tolog.TologProcessingException; ! import org.tmapiutils.query.tolog.parser.TologQuery; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class PreparedQueryImpl implements PreparedQuery { ! ! private TologQuery m_query; ! ! public PreparedQueryImpl(TologQuery q) { ! m_query = q; ! rewrite(); ! } ! ! /** ! * Rewrite the query for optimisation purposes ! */ ! private void rewrite() { ! // TODO Implement query rewriting optimisation strategy. ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.PreparedQuery#getQueryString() ! */ ! public String getQueryString() { ! return m_query.toString(); ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.PreparedQuery#execute() ! */ ! public TologResultsSet execute() throws TologProcessingException { ! return m_query.execute(); ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.PreparedQuery#execute(java.lang.Object[]) ! */ ! public TologResultsSet execute(Object[] params) throws TologProcessingException { ! return m_query.execute(params); ! } ! ! } Index: QueryEvaluatorImpl.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/memory/QueryEvaluatorImpl.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** QueryEvaluatorImpl.java 8 Mar 2005 12:33:40 -0000 1.2 --- QueryEvaluatorImpl.java 8 Jul 2005 16:03:19 -0000 1.3 *************** *** 1,209 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.memory; ! ! import java.io.IOException; ! import java.io.InputStream; ! import java.io.StringReader; ! import java.util.HashMap; ! import java.util.Map; ! ! import org.tmapiutils.query.tolog.TologResultsSet; ! import org.tmapiutils.query.tolog.PreparedQuery; ! import org.tmapiutils.query.tolog.QueryEvaluator; ! import org.tmapiutils.query.tolog.TologParserException; ! import org.tmapiutils.query.tolog.TologProcessingException; ! import org.tmapiutils.query.tolog.parser.Predicate; ! import org.tmapiutils.query.tolog.parser.TologLexer; ! import org.tmapiutils.query.tolog.parser.TologParser; ! import org.tmapiutils.query.tolog.parser.TologQuery; ! import org.tmapiutils.query.tolog.parser.TologRule; ! import org.tmapiutils.query.tolog.predicates.AssociationPredicate; ! import org.tmapiutils.query.tolog.predicates.AssociationRolePredicate; ! import org.tmapiutils.query.tolog.predicates.BaseLocatorPredicate; ! import org.tmapiutils.query.tolog.predicates.DirectInstanceOfPredicate; ! import org.tmapiutils.query.tolog.predicates.InstanceOfPredicate; ! import org.tmapiutils.query.tolog.predicates.OccurrencePredicate; ! import org.tmapiutils.query.tolog.predicates.ReifiesPredicate; ! import org.tmapiutils.query.tolog.predicates.ResourcePredicate; ! import org.tmapiutils.query.tolog.predicates.RolePlayerPredicate; ! import org.tmapiutils.query.tolog.predicates.ScopePredicate; ! import org.tmapiutils.query.tolog.predicates.SourceLocatorsPredicate; ! import org.tmapiutils.query.tolog.predicates.SubjectLocatorPredicate; ! import org.tmapiutils.query.tolog.predicates.SubjectIdentifierPredicate; ! import org.tmapiutils.query.tolog.predicates.TopicMapPredicate; ! import org.tmapiutils.query.tolog.predicates.TopicPredicate; ! import org.tmapiutils.query.tolog.predicates.TopicNamePredicate; ! import org.tmapiutils.query.tolog.predicates.TypePredicate; ! import org.tmapiutils.query.tolog.predicates.ValueLikePredicate; ! import org.tmapiutils.query.tolog.predicates.ValuePredicate; ! import org.tmapiutils.query.tolog.predicates.VariantPredicate; ! import org.tmapi.core.TopicMap; ! ! import antlr.ANTLRException; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class QueryEvaluatorImpl implements QueryEvaluator { ! ! private TopicMap m_tm; ! ! private Map m_rulesByName = null; ! private Map m_rulesByPrefix = null; ! private Map m_predicatesByName = null; ! ! public QueryEvaluatorImpl(TopicMap tm) { ! m_rulesByName = new HashMap(); ! m_rulesByPrefix = new HashMap(); ! m_predicatesByName = new HashMap(); ! initialisePredicates(); ! setTopicMap(tm); ! } ! ! /** ! * Loads the default built-in predicates ! */ ! private void initialisePredicates() { ! registerPredicateClass(AssociationPredicate.PREDICATE_NAME, AssociationPredicate.class); ! registerPredicateClass(AssociationRolePredicate.PREDICATE_NAME, AssociationRolePredicate.class); ! registerPredicateClass(BaseLocatorPredicate.PREDICATE_NAME, BaseLocatorPredicate.class); ! registerPredicateClass(DirectInstanceOfPredicate.PREDICATE_NAME, DirectInstanceOfPredicate.class); ! registerPredicateClass(InstanceOfPredicate.PREDICATE_NAME, InstanceOfPredicate.class); ! registerPredicateClass(OccurrencePredicate.PREDICATE_NAME, OccurrencePredicate.class); ! registerPredicateClass(ReifiesPredicate.PREDICATE_NAME, ReifiesPredicate.class); ! registerPredicateClass(ResourcePredicate.PREDICATE_NAME, ResourcePredicate.class); ! registerPredicateClass(RolePlayerPredicate.PREDICATE_NAME, RolePlayerPredicate.class); ! registerPredicateClass(ScopePredicate.PREDICATE_NAME, ScopePredicate.class); ! registerPredicateClass(SourceLocatorsPredicate.PREDICATE_NAME, SourceLocatorsPredicate.class); ! registerPredicateClass(SubjectLocatorPredicate.PREDICATE_NAME, SubjectLocatorPredicate.class); ! registerPredicateClass(SubjectIdentifierPredicate.PREDICATE_NAME, SubjectIdentifierPredicate.class); ! registerPredicateClass(TopicMapPredicate.PREDICATE_NAME, TopicMapPredicate.class); ! registerPredicateClass(TopicPredicate.PREDICATE_NAME, TopicPredicate.class); ! registerPredicateClass(TopicNamePredicate.PREDICATE_NAME, TopicNamePredicate.class); ! registerPredicateClass(TypePredicate.PREDICATE_NAME, TypePredicate.class); ! registerPredicateClass(ValueLikePredicate.PREDICATE_NAME, ValueLikePredicate.class); ! registerPredicateClass(ValuePredicate.PREDICATE_NAME, ValuePredicate.class); ! registerPredicateClass(VariantPredicate.PREDICATE_NAME, VariantPredicate.class); ! } ! ! public void setTopicMap(TopicMap tm) { ! m_tm = tm; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.QueryEvaluator#addRulesModule(java.io.InputStream, java.lang.String) ! */ ! public void addRulesModule(InputStream src, String prefix) ! throws IOException, TologParserException ! { ! try { ! TologParser p = new TologParser(new TologLexer(src)); ! p.setTopicMap(m_tm); ! p.setRules(m_rulesByName); ! p.setPredicates(m_predicatesByName); ! p.setPrefix(prefix); ! p.module(); ! m_rulesByName.putAll(p.getRules()); ! if (prefix != null) m_rulesByPrefix.put(prefix, p.getRules()); ! } catch (ANTLRException ex) { ! throw new TologParserException("Parser error reading module.", ex); ! } ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.QueryEvaluator#addRule(java.lang.String) ! */ ! public void addRule(String rule) throws TologParserException { ! try { ! TologParser p = new TologParser(new TologLexer(new StringReader(rule))); ! p.setTopicMap(m_tm); ! p.setRules(m_rulesByName); ! p.setPredicates(m_predicatesByName); ! TologRule r = p.rule(); ! m_rulesByName.put(r.getName(), r); ! m_predicatesByName.put(r.getName(), TologRule.class); ! } catch (ANTLRException ex) { ! throw new TologParserException("Parser error in rule string.", ex); ! } ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.QueryEvaluator#prepareQuery(java.lang.String) ! */ ! public PreparedQuery prepareQuery(String queryString) ! throws TologParserException, TologProcessingException ! { ! try { ! TologParser p = new TologParser(new TologLexer(new StringReader(queryString))); ! p.setTopicMap(m_tm); ! p.setPredicates(m_predicatesByName); ! p.setRules(m_rulesByName); ! p.setPrefixRules(m_rulesByPrefix); ! TologQuery q = p.query(); ! PreparedQuery pq = new PreparedQueryImpl(q); ! return pq; ! } catch (ANTLRException ex) { ! throw new TologParserException("Error parsing query string.", ex); ! } ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.QueryEvaluator#execute(java.lang.String) ! */ ! public TologResultsSet execute(String queryString) ! throws TologParserException, TologProcessingException ! { ! PreparedQuery pq = prepareQuery(queryString); ! return pq.execute(); ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.QueryEvaluator#execute(java.lang.String, java.lang.Object[]) ! */ ! public TologResultsSet execute(String queryString, Object[] queryParams) throws TologParserException, TologProcessingException { ! PreparedQuery pq = prepareQuery(queryString); ! return pq.execute(queryParams); ! } ! ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.QueryEvaluator#registerPredicateClass(java.lang.String, java.lang.Class) ! */ ! public void registerPredicateClass( ! String predicateName, ! Class predicateClass) ! throws IllegalArgumentException ! { ! if (!Predicate.class.isAssignableFrom(predicateClass)) { ! throw new IllegalArgumentException("Class does not implement the " + Predicate.class.getName() + " interface."); ! } ! ! m_predicatesByName.put(predicateName, predicateClass); ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.QueryEvaluator#getRegisteredPredicates() ! */ ! public Map getRegisteredPredicates() { ! return m_predicatesByName; ! } ! ! } --- 1,209 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.memory; ! ! import java.io.IOException; ! import java.io.InputStream; ! import java.io.StringReader; ! import java.util.HashMap; ! import java.util.Map; ! ! import org.tmapiutils.query.tolog.TologResultsSet; ! import org.tmapiutils.query.tolog.PreparedQuery; ! import org.tmapiutils.query.tolog.QueryEvaluator; ! import org.tmapiutils.query.tolog.TologParserException; ! import org.tmapiutils.query.tolog.TologProcessingException; ! import org.tmapiutils.query.tolog.parser.Predicate; ! import org.tmapiutils.query.tolog.parser.TologLexer; ! import org.tmapiutils.query.tolog.parser.TologParser; ! import org.tmapiutils.query.tolog.parser.TologQuery; ! import org.tmapiutils.query.tolog.parser.TologRule; ! import org.tmapiutils.query.tolog.predicates.AssociationPredicate; ! import org.tmapiutils.query.tolog.predicates.AssociationRolePredicate; ! import org.tmapiutils.query.tolog.predicates.BaseLocatorPredicate; ! import org.tmapiutils.query.tolog.predicates.DirectInstanceOfPredicate; ! import org.tmapiutils.query.tolog.predicates.InstanceOfPredicate; ! import org.tmapiutils.query.tolog.predicates.OccurrencePredicate; ! import org.tmapiutils.query.tolog.predicates.ReifiesPredicate; ! import org.tmapiutils.query.tolog.predicates.ResourcePredicate; ! import org.tmapiutils.query.tolog.predicates.RolePlayerPredicate; ! import org.tmapiutils.query.tolog.predicates.ScopePredicate; ! import org.tmapiutils.query.tolog.predicates.SourceLocatorsPredicate; ! import org.tmapiutils.query.tolog.predicates.SubjectLocatorPredicate; ! import org.tmapiutils.query.tolog.predicates.SubjectIdentifierPredicate; ! import org.tmapiutils.query.tolog.predicates.TopicMapPredicate; ! import org.tmapiutils.query.tolog.predicates.TopicPredicate; ! import org.tmapiutils.query.tolog.predicates.TopicNamePredicate; ! import org.tmapiutils.query.tolog.predicates.TypePredicate; ! import org.tmapiutils.query.tolog.predicates.ValueLikePredicate; ! import org.tmapiutils.query.tolog.predicates.ValuePredicate; ! import org.tmapiutils.query.tolog.predicates.VariantPredicate; ! import org.tmapi.core.TopicMap; ! ! import antlr.ANTLRException; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class QueryEvaluatorImpl implements QueryEvaluator { ! ! private TopicMap m_tm; ! ! private Map m_rulesByName = null; ! private Map m_rulesByPrefix = null; ! private Map m_predicatesByName = null; ! ! public QueryEvaluatorImpl(TopicMap tm) { ! m_rulesByName = new HashMap(); ! m_rulesByPrefix = new HashMap(); ! m_predicatesByName = new HashMap(); ! initialisePredicates(); ! setTopicMap(tm); ! } ! ! /** ! * Loads the default built-in predicates ! */ ! private void initialisePredicates() { ! registerPredicateClass(AssociationPredicate.PREDICATE_NAME, AssociationPredicate.class); ! registerPredicateClass(AssociationRolePredicate.PREDICATE_NAME, AssociationRolePredicate.class); ! registerPredicateClass(BaseLocatorPredicate.PREDICATE_NAME, BaseLocatorPredicate.class); ! registerPredicateClass(DirectInstanceOfPredicate.PREDICATE_NAME, DirectInstanceOfPredicate.class); ! registerPredicateClass(InstanceOfPredicate.PREDICATE_NAME, InstanceOfPredicate.class); ! registerPredicateClass(OccurrencePredicate.PREDICATE_NAME, OccurrencePredicate.class); ! registerPredicateClass(ReifiesPredicate.PREDICATE_NAME, ReifiesPredicate.class); ! registerPredicateClass(ResourcePredicate.PREDICATE_NAME, ResourcePredicate.class); ! registerPredicateClass(RolePlayerPredicate.PREDICATE_NAME, RolePlayerPredicate.class); ! registerPredicateClass(ScopePredicate.PREDICATE_NAME, ScopePredicate.class); ! registerPredicateClass(SourceLocatorsPredicate.PREDICATE_NAME, SourceLocatorsPredicate.class); ! registerPredicateClass(SubjectLocatorPredicate.PREDICATE_NAME, SubjectLocatorPredicate.class); ! registerPredicateClass(SubjectIdentifierPredicate.PREDICATE_NAME, SubjectIdentifierPredicate.class); ! registerPredicateClass(TopicMapPredicate.PREDICATE_NAME, TopicMapPredicate.class); ! registerPredicateClass(TopicPredicate.PREDICATE_NAME, TopicPredicate.class); ! registerPredicateClass(TopicNamePredicate.PREDICATE_NAME, TopicNamePredicate.class); ! registerPredicateClass(TypePredicate.PREDICATE_NAME, TypePredicate.class); ! registerPredicateClass(ValueLikePredicate.PREDICATE_NAME, ValueLikePredicate.class); ! registerPredicateClass(ValuePredicate.PREDICATE_NAME, ValuePredicate.class); ! registerPredicateClass(VariantPredicate.PREDICATE_NAME, VariantPredicate.class); ! } ! ! public void setTopicMap(TopicMap tm) { ! m_tm = tm; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.QueryEvaluator#addRulesModule(java.io.InputStream, java.lang.String) ! */ ! public void addRulesModule(InputStream src, String prefix) ! throws IOException, TologParserException ! { ! try { ! TologParser p = new TologParser(new TologLexer(src)); ! p.setTopicMap(m_tm); ! p.setRules(m_rulesByName); ! p.setPredicates(m_predicatesByName); ! p.setPrefix(prefix); ! p.module(); ! m_rulesByName.putAll(p.getRules()); ! if (prefix != null) m_rulesByPrefix.put(prefix, p.getRules()); ! } catch (ANTLRException ex) { ! throw new TologParserException("Parser error reading module.", ex); ! } ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.QueryEvaluator#addRule(java.lang.String) ! */ ! public void addRule(String rule) throws TologParserException { ! try { ! TologParser p = new TologParser(new TologLexer(new StringReader(rule))); ! p.setTopicMap(m_tm); ! p.setRules(m_rulesByName); ! p.setPredicates(m_predicatesByName); ! TologRule r = p.rule(); ! m_rulesByName.put(r.getName(), r); ! m_predicatesByName.put(r.getName(), TologRule.class); ! } catch (ANTLRException ex) { ! throw new TologParserException("Parser error in rule string.", ex); ! } ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.QueryEvaluator#prepareQuery(java.lang.String) ! */ ! public PreparedQuery prepareQuery(String queryString) ! throws TologParserException, TologProcessingException ! { ! try { ! TologParser p = new TologParser(new TologLexer(new StringReader(queryString))); ! p.setTopicMap(m_tm); ! p.setPredicates(m_predicatesByName); ! p.setRules(m_rulesByName); ! p.setPrefixRules(m_rulesByPrefix); ! TologQuery q = p.query(); ! PreparedQuery pq = new PreparedQueryImpl(q); ! return pq; ! } catch (ANTLRException ex) { ! throw new TologParserException("Error parsing query string.", ex); ! } ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.QueryEvaluator#execute(java.lang.String) ! */ ! public TologResultsSet execute(String queryString) ! throws TologParserException, TologProcessingException ! { ! PreparedQuery pq = prepareQuery(queryString); ! return pq.execute(); ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.QueryEvaluator#execute(java.lang.String, java.lang.Object[]) ! */ ! public TologResultsSet execute(String queryString, Object[] queryParams) throws TologParserException, TologProcessingException { ! PreparedQuery pq = prepareQuery(queryString); ! return pq.execute(queryParams); ! } ! ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.QueryEvaluator#registerPredicateClass(java.lang.String, java.lang.Class) ! */ ! public void registerPredicateClass( ! String predicateName, ! Class predicateClass) ! throws IllegalArgumentException ! { ! if (!Predicate.class.isAssignableFrom(predicateClass)) { ! throw new IllegalArgumentException("Class does not implement the " + Predicate.class.getName() + " interface."); ! } ! ! m_predicatesByName.put(predicateName, predicateClass); ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.QueryEvaluator#getRegisteredPredicates() ! */ ! public Map getRegisteredPredicates() { ! return m_predicatesByName; ! } ! ! } |
Update of /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30131/src/org/tmapiutils/query/tolog/predicates Modified Files: AssociationPredicate.java AssociationRolePredicate.java BaseLocatorPredicate.java DirectInstanceOfPredicate.java DynamicAssociationPredicate.java InstanceOfPredicate.java OccurrencePredicate.java PredicateBase.java ReifiesPredicate.java ResourcePredicate.java RolePlayerPredicate.java ScopePredicate.java SourceLocatorsPredicate.java SubjectIdentifierPredicate.java SubjectLocatorPredicate.java TopicMapPredicate.java TopicNamePredicate.java TopicPredicate.java TypePredicate.java ValueLikePredicate.java ValuePredicate.java VariantPredicate.java Log Message: Tabs -> Whitespaces Index: TopicPredicate.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/TopicPredicate.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TopicPredicate.java 8 Mar 2005 12:33:57 -0000 1.2 --- TopicPredicate.java 8 Jul 2005 16:03:20 -0000 1.3 *************** *** 1,72 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.predicates; ! ! import java.util.Iterator; ! import java.util.List; ! ! import org.tmapiutils.query.tolog.TologProcessingException; ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! import org.tmapi.core.Topic; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class TopicPredicate extends PredicateBase { ! ! public static final String PREDICATE_NAME = "topic"; ! private static final ParameterInfo[] PARAM_INFO = new ParameterInfo[] { ! new ParameterInfo(true, Object.class) ! }; ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getParamInfo() ! */ ! public ParameterInfo[] getParamInfo() { ! return PARAM_INFO; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getPredicateName() ! */ ! public String getPredicateName() { ! return PREDICATE_NAME; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.parser.Predicate#matches(java.util.List) ! */ ! public VariableSet matches(List params) throws TologProcessingException { ! VariableSet ret = new VariableSet(); ! initialiseResultsSet(ret); ! Object p = params.get(0); ! if (p instanceof Variable) { ! Iterator it = getTopicMap().getTopics().iterator(); ! while (it.hasNext()) { ! addResultsRow(ret, new Object[] {it.next()}); ! } ! } else if (p instanceof Topic) { ! addResultsRow(ret, new Object[] {p}); ! } ! return ret; ! } ! ! } --- 1,72 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.predicates; ! ! import java.util.Iterator; ! import java.util.List; ! ! import org.tmapiutils.query.tolog.TologProcessingException; ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! import org.tmapi.core.Topic; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class TopicPredicate extends PredicateBase { ! ! public static final String PREDICATE_NAME = "topic"; ! private static final ParameterInfo[] PARAM_INFO = new ParameterInfo[] { ! new ParameterInfo(true, Object.class) ! }; ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getParamInfo() ! */ ! public ParameterInfo[] getParamInfo() { ! return PARAM_INFO; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getPredicateName() ! */ ! public String getPredicateName() { ! return PREDICATE_NAME; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.parser.Predicate#matches(java.util.List) ! */ ! public VariableSet matches(List params) throws TologProcessingException { ! VariableSet ret = new VariableSet(); ! initialiseResultsSet(ret); ! Object p = params.get(0); ! if (p instanceof Variable) { ! Iterator it = getTopicMap().getTopics().iterator(); ! while (it.hasNext()) { ! addResultsRow(ret, new Object[] {it.next()}); ! } ! } else if (p instanceof Topic) { ! addResultsRow(ret, new Object[] {p}); ! } ! return ret; ! } ! ! } Index: AssociationPredicate.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/AssociationPredicate.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** AssociationPredicate.java 9 Mar 2005 12:40:19 -0000 1.3 --- AssociationPredicate.java 8 Jul 2005 16:03:20 -0000 1.4 *************** *** 1,74 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.predicates; ! ! import java.util.Iterator; ! import java.util.List; ! ! import org.tmapiutils.query.tolog.TologProcessingException; ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! // TMAPI ! import org.tmapi.core.Association; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class AssociationPredicate extends PredicateBase { ! ! public static final String PREDICATE_NAME = "association"; ! private static final ParameterInfo[] PARAM_INFO = new ParameterInfo[] { ! new ParameterInfo(true, Object.class) ! }; ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getParamInfo() ! */ ! public ParameterInfo[] getParamInfo() { ! return PARAM_INFO; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getPredicateName() ! */ ! public String getPredicateName() { ! return PREDICATE_NAME; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.parser.Predicate#matches(java.util.List) ! */ ! public VariableSet matches(List params) throws TologProcessingException { ! VariableSet ret = new VariableSet(); ! initialiseResultsSet(ret); ! Object p = params.get(0); ! if (p instanceof Variable) { ! Iterator it = getTopicMap().getAssociations().iterator(); ! while (it.hasNext()) { ! addResultsRow(ret, new Object[] {it.next()}); ! } ! } else if (p instanceof Association) { ! addResultsRow(ret, new Object[] {p}); ! } ! return ret; ! } ! ! } ! --- 1,74 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.predicates; ! ! import java.util.Iterator; ! import java.util.List; ! ! import org.tmapiutils.query.tolog.TologProcessingException; ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! // TMAPI ! import org.tmapi.core.Association; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class AssociationPredicate extends PredicateBase { ! ! public static final String PREDICATE_NAME = "association"; ! private static final ParameterInfo[] PARAM_INFO = new ParameterInfo[] { ! new ParameterInfo(true, Object.class) ! }; ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getParamInfo() ! */ ! public ParameterInfo[] getParamInfo() { ! return PARAM_INFO; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getPredicateName() ! */ ! public String getPredicateName() { ! return PREDICATE_NAME; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.parser.Predicate#matches(java.util.List) ! */ ! public VariableSet matches(List params) throws TologProcessingException { ! VariableSet ret = new VariableSet(); ! initialiseResultsSet(ret); ! Object p = params.get(0); ! if (p instanceof Variable) { ! Iterator it = getTopicMap().getAssociations().iterator(); ! while (it.hasNext()) { ! addResultsRow(ret, new Object[] {it.next()}); ! } ! } else if (p instanceof Association) { ! addResultsRow(ret, new Object[] {p}); ! } ! return ret; ! } ! ! } ! Index: TopicMapPredicate.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/TopicMapPredicate.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** TopicMapPredicate.java 9 Mar 2005 12:40:19 -0000 1.4 --- TopicMapPredicate.java 8 Jul 2005 16:03:20 -0000 1.5 *************** *** 1,72 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.predicates; ! ! import java.util.List; ! ! import org.tmapiutils.query.tolog.TologProcessingException; ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! // TMAPI ! import org.tmapi.core.TopicMap; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class TopicMapPredicate extends PredicateBase { ! ! public static final String PREDICATE_NAME = "topicmap"; ! private static final ParameterInfo [] PARAM_INFO = new ParameterInfo [] { ! new ParameterInfo(true) ! }; ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getParamInfo() ! */ ! public ParameterInfo[] getParamInfo() { ! return PARAM_INFO; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getPredicateName() ! */ ! public String getPredicateName() { ! return PREDICATE_NAME; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.parser.Predicate#matches(java.util.List) ! */ ! public VariableSet matches(List params) throws TologProcessingException { ! VariableSet ret = new VariableSet(); ! initialiseResultsSet(ret); ! if (params.get(0) instanceof Variable) { ! addResultsRow(ret, new Object[] { getTopicMap()}); ! } else if (params.get(0) instanceof TopicMap) { ! TopicMap topicmap = (TopicMap)params.get(0); ! if (getTopicMap().equals(topicmap)) { ! addResultsRow(ret, new Object[] { topicmap }); ! } ! } ! return ret; ! } ! ! } ! --- 1,72 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.predicates; ! ! import java.util.List; ! ! import org.tmapiutils.query.tolog.TologProcessingException; ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! // TMAPI ! import org.tmapi.core.TopicMap; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class TopicMapPredicate extends PredicateBase { ! ! public static final String PREDICATE_NAME = "topicmap"; ! private static final ParameterInfo [] PARAM_INFO = new ParameterInfo [] { ! new ParameterInfo(true) ! }; ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getParamInfo() ! */ ! public ParameterInfo[] getParamInfo() { ! return PARAM_INFO; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getPredicateName() ! */ ! public String getPredicateName() { ! return PREDICATE_NAME; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.parser.Predicate#matches(java.util.List) ! */ ! public VariableSet matches(List params) throws TologProcessingException { ! VariableSet ret = new VariableSet(); ! initialiseResultsSet(ret); ! if (params.get(0) instanceof Variable) { ! addResultsRow(ret, new Object[] { getTopicMap()}); ! } else if (params.get(0) instanceof TopicMap) { ! TopicMap topicmap = (TopicMap)params.get(0); ! if (getTopicMap().equals(topicmap)) { ! addResultsRow(ret, new Object[] { topicmap }); ! } ! } ! return ret; ! } ! ! } ! Index: ValuePredicate.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/ValuePredicate.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ValuePredicate.java 9 Mar 2005 12:40:19 -0000 1.5 --- ValuePredicate.java 8 Jul 2005 16:03:20 -0000 1.6 *************** *** 1,226 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.predicates; ! ! import java.util.ArrayList; ! import java.util.Iterator; ! import java.util.List; ! ! import org.tmapiutils.query.tolog.TologParserException; ! import org.tmapiutils.query.tolog.TologProcessingException; ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! // TMAPI ! import org.tmapi.core.TopicMapObject; ! import org.tmapi.core.TopicMap; ! import org.tmapi.core.Topic; ! import org.tmapi.core.Occurrence; ! import org.tmapi.core.TopicName; ! import org.tmapi.core.Variant; ! import org.tmapi.core.TMAPIException; ! import org.tmapi.index.core.TopicNamesIndex; ! import org.tmapi.index.core.OccurrencesIndex; ! import org.tmapi.index.core.VariantsIndex; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class ValuePredicate extends PredicateBase { ! ! private OccurrencesIndex _occIdx; ! private TopicNamesIndex _tnIdx; ! private VariantsIndex _varIdx; ! ! public static final String PREDICATE_NAME = "value"; ! private static final ParameterInfo[] PARAM_INFO = new ParameterInfo[] { ! new ParameterInfo(true), ! new ParameterInfo(true) ! }; ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getParamInfo() ! */ ! public ParameterInfo[] getParamInfo() { ! return PARAM_INFO; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getPredicateName() ! */ ! public String getPredicateName() { ! return PREDICATE_NAME; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.parser.Predicate#matches(java.util.List) ! */ ! public VariableSet matches(List params) throws TologProcessingException { ! Object obj = params.get(0); ! Object val = params.get(1); ! VariableSet ret = new VariableSet(); ! initialiseResultsSet(ret); ! if ((obj instanceof TopicMapObject) && (val instanceof Variable)) { ! matchValue((TopicMapObject)obj, ret); ! } else if ((obj instanceof Variable) && (val instanceof String)) { ! matchObject((String)val, ret); ! } else if ((obj instanceof TopicMapObject) && (val instanceof String)) { ! closedMatch((TopicMapObject)obj, (String)val, ret); ! } else if ((obj instanceof Variable) && (val instanceof Variable)) { ! openMatch(ret); ! } ! return ret; ! } ! ! ! private String getValue(TopicMapObject tmObj) { ! String value = null; ! if (tmObj instanceof Occurrence) { ! value = ((Occurrence) tmObj).getValue(); ! } ! else if (tmObj instanceof TopicName) { ! value = ((TopicName) tmObj).getValue(); ! } ! else if (tmObj instanceof Variant) { ! value = ((Variant) tmObj).getValue(); ! } ! return value; ! } ! ! /** ! * @param object ! * @param ret ! */ ! private void matchValue(TopicMapObject object, VariableSet ret) throws TologProcessingException { ! ! String value = getValue(object); ! if (value != null) { ! addResultsRow(ret, new Object[] {object, value}); ! } ! } ! ! /** ! * @param string ! * @param ret ! */ ! private void matchObject(String data, VariableSet ret) throws TologProcessingException ! { ! try { ! _occIdx.open(); ! if (!_occIdx.getFlags().isAutoUpdated()) { ! _occIdx.reindex(); ! } ! _tnIdx.open(); ! if (!_tnIdx.getFlags().isAutoUpdated()) { ! _tnIdx.reindex(); ! } ! _varIdx.open(); ! if (!_varIdx.getFlags().isAutoUpdated()) { ! _varIdx.reindex(); ! } ! } ! catch (TMAPIException ex) { ! throw new TologProcessingException("Error initialising indexes for " + PREDICATE_NAME, ex); ! } ! for (Iterator it = _occIdx.getOccurrencesByValue(data).iterator(); it.hasNext();) { ! addResultsRow(ret, new Object[] {it.next(), data}); ! } ! for (Iterator it = _tnIdx.getTopicNamesByValue(data).iterator(); it.hasNext();) { ! addResultsRow(ret, new Object[] { it.next(), data }); ! } ! for (Iterator it = _varIdx.getVariantsByValue(data).iterator(); it.hasNext();) { ! addResultsRow(ret, new Object[] { it.next(), data }); ! } ! } ! ! /** ! * @param object ! * @param string ! * @param ret ! */ ! private void closedMatch(TopicMapObject object, String data, VariableSet ret) throws TologProcessingException { ! ! String value = getValue(object); ! if ((value != null) && value.equals(data)) { ! addResultsRow(ret, new Object[] { object, data }); ! } ! } ! ! /** ! * @param ret ! */ ! private void openMatch(VariableSet ret) throws TologProcessingException { ! ValuesExtractor vx = new ValuesExtractor(ret); ! for (Iterator it = getTopicMap().getTopics().iterator(); it.hasNext();) { ! vx.extractValues((Topic)it.next()); ! } ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.parser.Predicate#initialise(org.tmapi.core.TopicMap) ! */ ! public void initialise(TopicMap tm) throws TologParserException { ! super.initialise(tm); ! try { ! _occIdx = (OccurrencesIndex) tm.getHelperObject(OccurrencesIndex.class); ! _varIdx = (VariantsIndex) tm.getHelperObject(VariantsIndex.class); ! _tnIdx = (TopicNamesIndex) tm.getHelperObject(TopicNamesIndex.class); ! } catch (TMAPIException ex) { ! throw new TologParserException("Error initialising indexes for " + PREDICATE_NAME, ex); ! } ! } ! ! private class ValuesExtractor { ! ! private VariableSet m_vs; ! ! public ValuesExtractor(VariableSet vs) { ! m_vs = vs; ! } ! ! /* (non-Javadoc) ! * @see uk.co.jezuk.mango.UnaryFunction#fn(java.lang.Object) ! */ ! public void extractValues(Topic t) throws TologProcessingException { ! ArrayList ret = new ArrayList(); ! for (Iterator it = t.getTopicNames().iterator(); it.hasNext(); ) { ! TopicName bn = (TopicName)it.next(); ! addResultsRow(m_vs, new Object[] {bn, bn.getValue()}); ! addVariants(bn); ! } ! for (Iterator it = t.getOccurrences().iterator(); it.hasNext();) { ! Occurrence o = (Occurrence)it.next(); ! if (o.getValue() != null) { ! addResultsRow(m_vs, new Object[] { o, o.getValue() }); ! } ! } ! } ! ! private void addVariants(TopicName topicname) throws TologProcessingException { ! for (Iterator it = topicname.getVariants().iterator(); it.hasNext();) { ! Variant variant = (Variant) it.next(); ! String value = variant.getValue(); ! if (value != null) { ! addResultsRow(m_vs, new Object[] { variant, value }); ! } ! } ! } ! } ! } ! --- 1,226 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.predicates; ! ! import java.util.ArrayList; ! import java.util.Iterator; ! import java.util.List; ! ! import org.tmapiutils.query.tolog.TologParserException; ! import org.tmapiutils.query.tolog.TologProcessingException; ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! // TMAPI ! import org.tmapi.core.TopicMapObject; ! import org.tmapi.core.TopicMap; ! import org.tmapi.core.Topic; ! import org.tmapi.core.Occurrence; ! import org.tmapi.core.TopicName; ! import org.tmapi.core.Variant; ! import org.tmapi.core.TMAPIException; ! import org.tmapi.index.core.TopicNamesIndex; ! import org.tmapi.index.core.OccurrencesIndex; ! import org.tmapi.index.core.VariantsIndex; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class ValuePredicate extends PredicateBase { ! ! private OccurrencesIndex _occIdx; ! private TopicNamesIndex _tnIdx; ! private VariantsIndex _varIdx; ! ! public static final String PREDICATE_NAME = "value"; ! private static final ParameterInfo[] PARAM_INFO = new ParameterInfo[] { ! new ParameterInfo(true), ! new ParameterInfo(true) ! }; ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getParamInfo() ! */ ! public ParameterInfo[] getParamInfo() { ! return PARAM_INFO; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getPredicateName() ! */ ! public String getPredicateName() { ! return PREDICATE_NAME; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.parser.Predicate#matches(java.util.List) ! */ ! public VariableSet matches(List params) throws TologProcessingException { ! Object obj = params.get(0); ! Object val = params.get(1); ! VariableSet ret = new VariableSet(); ! initialiseResultsSet(ret); ! if ((obj instanceof TopicMapObject) && (val instanceof Variable)) { ! matchValue((TopicMapObject)obj, ret); ! } else if ((obj instanceof Variable) && (val instanceof String)) { ! matchObject((String)val, ret); ! } else if ((obj instanceof TopicMapObject) && (val instanceof String)) { ! closedMatch((TopicMapObject)obj, (String)val, ret); ! } else if ((obj instanceof Variable) && (val instanceof Variable)) { ! openMatch(ret); ! } ! return ret; ! } ! ! ! private String getValue(TopicMapObject tmObj) { ! String value = null; ! if (tmObj instanceof Occurrence) { ! value = ((Occurrence) tmObj).getValue(); ! } ! else if (tmObj instanceof TopicName) { ! value = ((TopicName) tmObj).getValue(); ! } ! else if (tmObj instanceof Variant) { ! value = ((Variant) tmObj).getValue(); ! } ! return value; ! } ! ! /** ! * @param object ! * @param ret ! */ ! private void matchValue(TopicMapObject object, VariableSet ret) throws TologProcessingException { ! ! String value = getValue(object); ! if (value != null) { ! addResultsRow(ret, new Object[] {object, value}); ! } ! } ! ! /** ! * @param string ! * @param ret ! */ ! private void matchObject(String data, VariableSet ret) throws TologProcessingException ! { ! try { ! _occIdx.open(); ! if (!_occIdx.getFlags().isAutoUpdated()) { ! _occIdx.reindex(); ! } ! _tnIdx.open(); ! if (!_tnIdx.getFlags().isAutoUpdated()) { ! _tnIdx.reindex(); ! } ! _varIdx.open(); ! if (!_varIdx.getFlags().isAutoUpdated()) { ! _varIdx.reindex(); ! } ! } ! catch (TMAPIException ex) { ! throw new TologProcessingException("Error initialising indexes for " + PREDICATE_NAME, ex); ! } ! for (Iterator it = _occIdx.getOccurrencesByValue(data).iterator(); it.hasNext();) { ! addResultsRow(ret, new Object[] {it.next(), data}); ! } ! for (Iterator it = _tnIdx.getTopicNamesByValue(data).iterator(); it.hasNext();) { ! addResultsRow(ret, new Object[] { it.next(), data }); ! } ! for (Iterator it = _varIdx.getVariantsByValue(data).iterator(); it.hasNext();) { ! addResultsRow(ret, new Object[] { it.next(), data }); ! } ! } ! ! /** ! * @param object ! * @param string ! * @param ret ! */ ! private void closedMatch(TopicMapObject object, String data, VariableSet ret) throws TologProcessingException { ! ! String value = getValue(object); ! if ((value != null) && value.equals(data)) { ! addResultsRow(ret, new Object[] { object, data }); ! } ! } ! ! /** ! * @param ret ! */ ! private void openMatch(VariableSet ret) throws TologProcessingException { ! ValuesExtractor vx = new ValuesExtractor(ret); ! for (Iterator it = getTopicMap().getTopics().iterator(); it.hasNext();) { ! vx.extractValues((Topic)it.next()); ! } ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.parser.Predicate#initialise(org.tmapi.core.TopicMap) ! */ ! public void initialise(TopicMap tm) throws TologParserException { ! super.initialise(tm); ! try { ! _occIdx = (OccurrencesIndex) tm.getHelperObject(OccurrencesIndex.class); ! _varIdx = (VariantsIndex) tm.getHelperObject(VariantsIndex.class); ! _tnIdx = (TopicNamesIndex) tm.getHelperObject(TopicNamesIndex.class); ! } catch (TMAPIException ex) { ! throw new TologParserException("Error initialising indexes for " + PREDICATE_NAME, ex); ! } ! } ! ! private class ValuesExtractor { ! ! private VariableSet m_vs; ! ! public ValuesExtractor(VariableSet vs) { ! m_vs = vs; ! } ! ! /* (non-Javadoc) ! * @see uk.co.jezuk.mango.UnaryFunction#fn(java.lang.Object) ! */ ! public void extractValues(Topic t) throws TologProcessingException { ! ArrayList ret = new ArrayList(); ! for (Iterator it = t.getTopicNames().iterator(); it.hasNext(); ) { ! TopicName bn = (TopicName)it.next(); ! addResultsRow(m_vs, new Object[] {bn, bn.getValue()}); ! addVariants(bn); ! } ! for (Iterator it = t.getOccurrences().iterator(); it.hasNext();) { ! Occurrence o = (Occurrence)it.next(); ! if (o.getValue() != null) { ! addResultsRow(m_vs, new Object[] { o, o.getValue() }); ! } ! } ! } ! ! private void addVariants(TopicName topicname) throws TologProcessingException { ! for (Iterator it = topicname.getVariants().iterator(); it.hasNext();) { ! Variant variant = (Variant) it.next(); ! String value = variant.getValue(); ! if (value != null) { ! addResultsRow(m_vs, new Object[] { variant, value }); ! } ! } ! } ! } ! } ! Index: ScopePredicate.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/ScopePredicate.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ScopePredicate.java 9 Mar 2005 12:40:19 -0000 1.4 --- ScopePredicate.java 8 Jul 2005 16:03:20 -0000 1.5 *************** *** 1,143 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.predicates; ! ! import java.util.Iterator; ! import java.util.List; ! ! import org.tmapiutils.query.tolog.TologParserException; ! import org.tmapiutils.query.tolog.TologProcessingException; ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! ! import org.tmapiutils.utils.IndexUtils; ! // TMAPI ! import org.tmapi.core.TopicMap; ! import org.tmapi.core.ScopedObject; ! import org.tmapi.core.Topic; ! import org.tmapi.core.TMAPIException; ! import org.tmapi.index.core.ScopedObjectsIndex; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class ScopePredicate extends PredicateBase { ! ! private ScopedObjectsIndex _scopeIdx; ! public static final String PREDICATE_NAME = "scope"; ! private static final ParameterInfo[] PARAM_INFO = new ParameterInfo[]{ ! new ParameterInfo(true), ! new ParameterInfo(true) ! }; ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getParamInfo() ! */ ! public ParameterInfo[] getParamInfo() { ! return PARAM_INFO; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getPredicateName() ! */ ! public String getPredicateName() { ! return PREDICATE_NAME; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.parser.Predicate#matches(java.util.List) ! */ ! public VariableSet matches(List params) throws TologProcessingException { ! Object scoped = params.get(0); ! Object theme = params.get(1); ! VariableSet ret = new VariableSet(); ! initialiseResultsSet(ret); ! if ((scoped instanceof ScopedObject) && (theme instanceof Variable)) { ! matchThemes((ScopedObject)scoped, ret); ! } else if ((scoped instanceof Variable) && (theme instanceof Topic)) { ! matchScopedObjects((Topic)theme, ret); ! } else if ((scoped instanceof ScopedObject) && (theme instanceof Topic)) { ! closedMatch((ScopedObject)scoped, (Topic)theme, ret); ! } else if ((scoped instanceof Variable) && (theme instanceof Variable)) { ! openMatch(ret); ! } ! return ret; ! } ! ! /** ! * @param ret ! */ ! private void openMatch(VariableSet ret) throws TologProcessingException { ! IndexUtils.updateIndex(_scopeIdx); ! for (Iterator themes = _scopeIdx.getScopingTopics().iterator(); themes.hasNext();){ ! Topic topic = (Topic) themes.next(); ! for (Iterator scoped = _scopeIdx.getScopedObjectsByScopingTopic(topic).iterator(); scoped.hasNext();) { ! addResultsRow(ret, new Object[] {scoped.next(), topic}); ! } ! } ! } ! ! /** ! * @param object ! * @param topic ! * @param ret ! */ ! private void closedMatch(ScopedObject scoped, Topic topic, VariableSet ret) throws TologProcessingException { ! for (Iterator it = scoped.getScope().iterator(); it.hasNext();) { ! if (it.next().equals(topic)) { ! addResultsRow(ret, new Object[] {scoped, topic}); ! } ! } ! } ! ! /** ! * @param topic ! * @param ret ! */ ! private void matchScopedObjects(Topic topic, VariableSet ret) throws TologProcessingException { ! IndexUtils.updateIndex(_scopeIdx); ! for (Iterator it = _scopeIdx.getScopedObjectsByScopingTopic(topic).iterator(); it.hasNext();) { ! addResultsRow(ret, new Object[] {it.next(), topic}); ! } ! } ! ! /** ! * @param object ! * @param ret ! */ ! private void matchThemes(ScopedObject scoped, VariableSet ret) throws TologProcessingException { ! for (Iterator it = scoped.getScope().iterator(); it.hasNext();) { ! addResultsRow(ret, new Object[] { scoped, it.next()}); ! } ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.parser.Predicate#initialise(org.tmapi.core.TopicMap) ! */ ! public void initialise(TopicMap tm) throws TologParserException { ! super.initialise(tm); ! try { ! _scopeIdx = (ScopedObjectsIndex) tm.getHelperObject(ScopedObjectsIndex.class); ! } catch (TMAPIException ex) { ! throw new TologParserException("Unable to initialise indexes for " + PREDICATE_NAME, ex); ! } ! } ! ! } --- 1,143 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.predicates; ! ! import java.util.Iterator; ! import java.util.List; ! ! import org.tmapiutils.query.tolog.TologParserException; ! import org.tmapiutils.query.tolog.TologProcessingException; ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! ! import org.tmapiutils.utils.IndexUtils; ! // TMAPI ! import org.tmapi.core.TopicMap; ! import org.tmapi.core.ScopedObject; ! import org.tmapi.core.Topic; ! import org.tmapi.core.TMAPIException; ! import org.tmapi.index.core.ScopedObjectsIndex; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class ScopePredicate extends PredicateBase { ! ! private ScopedObjectsIndex _scopeIdx; ! public static final String PREDICATE_NAME = "scope"; ! private static final ParameterInfo[] PARAM_INFO = new ParameterInfo[]{ ! new ParameterInfo(true), ! new ParameterInfo(true) ! }; ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getParamInfo() ! */ ! public ParameterInfo[] getParamInfo() { ! return PARAM_INFO; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getPredicateName() ! */ ! public String getPredicateName() { ! return PREDICATE_NAME; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.parser.Predicate#matches(java.util.List) ! */ ! public VariableSet matches(List params) throws TologProcessingException { ! Object scoped = params.get(0); ! Object theme = params.get(1); ! VariableSet ret = new VariableSet(); ! initialiseResultsSet(ret); ! if ((scoped instanceof ScopedObject) && (theme instanceof Variable)) { ! matchThemes((ScopedObject)scoped, ret); ! } else if ((scoped instanceof Variable) && (theme instanceof Topic)) { ! matchScopedObjects((Topic)theme, ret); ! } else if ((scoped instanceof ScopedObject) && (theme instanceof Topic)) { ! closedMatch((ScopedObject)scoped, (Topic)theme, ret); ! } else if ((scoped instanceof Variable) && (theme instanceof Variable)) { ! openMatch(ret); ! } ! return ret; ! } ! ! /** ! * @param ret ! */ ! private void openMatch(VariableSet ret) throws TologProcessingException { ! IndexUtils.updateIndex(_scopeIdx); ! for (Iterator themes = _scopeIdx.getScopingTopics().iterator(); themes.hasNext();){ ! Topic topic = (Topic) themes.next(); ! for (Iterator scoped = _scopeIdx.getScopedObjectsByScopingTopic(topic).iterator(); scoped.hasNext();) { ! addResultsRow(ret, new Object[] {scoped.next(), topic}); ! } ! } ! } ! ! /** ! * @param object ! * @param topic ! * @param ret ! */ ! private void closedMatch(ScopedObject scoped, Topic topic, VariableSet ret) throws TologProcessingException { ! for (Iterator it = scoped.getScope().iterator(); it.hasNext();) { ! if (it.next().equals(topic)) { ! addResultsRow(ret, new Object[] {scoped, topic}); ! } ! } ! } ! ! /** ! * @param topic ! * @param ret ! */ ! private void matchScopedObjects(Topic topic, VariableSet ret) throws TologProcessingException { ! IndexUtils.updateIndex(_scopeIdx); ! for (Iterator it = _scopeIdx.getScopedObjectsByScopingTopic(topic).iterator(); it.hasNext();) { ! addResultsRow(ret, new Object[] {it.next(), topic}); ! } ! } ! ! /** ! * @param object ! * @param ret ! */ ! private void matchThemes(ScopedObject scoped, VariableSet ret) throws TologProcessingException { ! for (Iterator it = scoped.getScope().iterator(); it.hasNext();) { ! addResultsRow(ret, new Object[] { scoped, it.next()}); ! } ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.parser.Predicate#initialise(org.tmapi.core.TopicMap) ! */ ! public void initialise(TopicMap tm) throws TologParserException { ! super.initialise(tm); ! try { ! _scopeIdx = (ScopedObjectsIndex) tm.getHelperObject(ScopedObjectsIndex.class); ! } catch (TMAPIException ex) { ! throw new TologParserException("Unable to initialise indexes for " + PREDICATE_NAME, ex); ! } ! } ! ! } Index: AssociationRolePredicate.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/AssociationRolePredicate.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** AssociationRolePredicate.java 8 Mar 2005 12:33:56 -0000 1.4 --- AssociationRolePredicate.java 8 Jul 2005 16:03:20 -0000 1.5 *************** *** 1,115 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.predicates; ! ! import java.util.Iterator; ! import java.util.List; ! ! import org.tmapiutils.query.tolog.TologProcessingException; ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! // TMAPI ! import org.tmapi.core.Association; ! import org.tmapi.core.AssociationRole; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class AssociationRolePredicate extends PredicateBase { ! ! public static final String PREDICATE_NAME = "association-role"; ! private static final ParameterInfo[] PARAM_INFO = new ParameterInfo[] { ! new ParameterInfo(true, Object.class), ! new ParameterInfo(true, Object.class) ! }; ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getParamInfo() ! */ ! public ParameterInfo[] getParamInfo() { ! return PARAM_INFO; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getPredicateName() ! */ ! public String getPredicateName() { ! return PREDICATE_NAME; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.parser.Predicate#matches(java.util.List) ! */ ! public VariableSet matches(List params) throws TologProcessingException { ! Object assoc = params.get(0); ! Object role = params.get(1); ! VariableSet ret = new VariableSet(); ! initialiseResultsSet(ret); ! ! if ((assoc instanceof Association) && (role instanceof Variable)) { ! matchRoles((Association)assoc, ret); ! } else if ((assoc instanceof Variable) && (role instanceof AssociationRole)) { ! addResultsRow(ret, new Object[] {((AssociationRole)role).getAssociation(), role}); ! } else if ((assoc instanceof Variable) && (role instanceof Variable)) { ! openMatch(ret); ! } else if ((assoc instanceof Association) && (role instanceof AssociationRole)) { ! closedMatch((Association)assoc, (AssociationRole)role, ret); ! } ! return ret; ! } ! ! /** ! * @param association ! * @param member ! * @param ret ! */ ! private void closedMatch(Association association, AssociationRole role, VariableSet ret) throws TologProcessingException { ! if (role.getAssociation().equals(association)) { ! addResultsRow(ret, new Object[] {association, role}); ! } ! } ! ! /** ! * @param ret ! */ ! private void openMatch(VariableSet ret) throws TologProcessingException { ! Iterator it = getTopicMap().getAssociations().iterator(); ! while (it.hasNext()) { ! Association assoc = (Association)it.next(); ! Iterator roles = assoc.getAssociationRoles().iterator(); ! while (roles.hasNext()) { ! addResultsRow(ret, new Object[] {assoc, roles.next()}); ! } ! } ! } ! ! /** ! * @param association ! * @param ret ! */ ! private void matchRoles(Association association, VariableSet ret) throws TologProcessingException { ! Iterator it = association.getAssociationRoles().iterator(); ! while (it.hasNext()) { ! addResultsRow(ret, new Object[] {association, it.next()}); ! } ! } ! ! } ! --- 1,115 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.predicates; ! ! import java.util.Iterator; ! import java.util.List; ! ! import org.tmapiutils.query.tolog.TologProcessingException; ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! // TMAPI ! import org.tmapi.core.Association; ! import org.tmapi.core.AssociationRole; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class AssociationRolePredicate extends PredicateBase { ! ! public static final String PREDICATE_NAME = "association-role"; ! private static final ParameterInfo[] PARAM_INFO = new ParameterInfo[] { ! new ParameterInfo(true, Object.class), ! new ParameterInfo(true, Object.class) ! }; ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getParamInfo() ! */ ! public ParameterInfo[] getParamInfo() { ! return PARAM_INFO; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getPredicateName() ! */ ! public String getPredicateName() { ! return PREDICATE_NAME; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.parser.Predicate#matches(java.util.List) ! */ ! public VariableSet matches(List params) throws TologProcessingException { ! Object assoc = params.get(0); ! Object role = params.get(1); ! VariableSet ret = new VariableSet(); ! initialiseResultsSet(ret); ! ! if ((assoc instanceof Association) && (role instanceof Variable)) { ! matchRoles((Association)assoc, ret); ! } else if ((assoc instanceof Variable) && (role instanceof AssociationRole)) { ! addResultsRow(ret, new Object[] {((AssociationRole)role).getAssociation(), role}); ! } else if ((assoc instanceof Variable) && (role instanceof Variable)) { ! openMatch(ret); ! } else if ((assoc instanceof Association) && (role instanceof AssociationRole)) { ! closedMatch((Association)assoc, (AssociationRole)role, ret); ! } ! return ret; ! } ! ! /** ! * @param association ! * @param member ! * @param ret ! */ ! private void closedMatch(Association association, AssociationRole role, VariableSet ret) throws TologProcessingException { ! if (role.getAssociation().equals(association)) { ! addResultsRow(ret, new Object[] {association, role}); ! } ! } ! ! /** ! * @param ret ! */ ! private void openMatch(VariableSet ret) throws TologProcessingException { ! Iterator it = getTopicMap().getAssociations().iterator(); ! while (it.hasNext()) { ! Association assoc = (Association)it.next(); ! Iterator roles = assoc.getAssociationRoles().iterator(); ! while (roles.hasNext()) { ! addResultsRow(ret, new Object[] {assoc, roles.next()}); ! } ! } ! } ! ! /** ! * @param association ! * @param ret ! */ ! private void matchRoles(Association association, VariableSet ret) throws TologProcessingException { ! Iterator it = association.getAssociationRoles().iterator(); ! while (it.hasNext()) { ! addResultsRow(ret, new Object[] {association, it.next()}); ! } ! } ! ! } ! Index: SubjectLocatorPredicate.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/SubjectLocatorPredicate.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** SubjectLocatorPredicate.java 8 Mar 2005 12:33:57 -0000 1.4 --- SubjectLocatorPredicate.java 8 Jul 2005 16:03:20 -0000 1.5 *************** *** 1,142 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.predicates; ! ! import java.util.Iterator; ! import java.util.List; ! ! import org.tmapiutils.query.tolog.TologParserException; ! import org.tmapiutils.query.tolog.TologProcessingException; ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! ! import org.tmapiutils.utils.IndexUtils; ! // TMAPI ! import org.tmapi.core.Locator; ! import org.tmapi.core.TopicMap; ! import org.tmapi.core.Topic; ! import org.tmapi.core.TMAPIException; ! import org.tmapi.index.core.TopicsIndex; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class SubjectLocatorPredicate extends PredicateBase { ! ! private TopicsIndex _topicsIdx; ! public static final String PREDICATE_NAME = "subject-locator"; ! private static final ParameterInfo[] PARAM_INFO = new ParameterInfo[] { ! new ParameterInfo(true), ! new ParameterInfo(true) ! }; ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getParamInfo() ! */ ! public ParameterInfo[] getParamInfo() { ! return PARAM_INFO; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getPredicateName() ! */ ! public String getPredicateName() { ! return PREDICATE_NAME; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.parser.Predicate#matches(java.util.List) ! */ ! public VariableSet matches(List params) throws TologProcessingException { ! Object topic = params.get(0); ! Object loc = params.get(1); ! VariableSet ret = new VariableSet(); ! initialiseResultsSet(ret); ! ! if ((topic instanceof Topic) && (loc instanceof Variable)) { ! matchSubjectLocator((Topic)topic, ret); ! } else if ((topic instanceof Variable) && (loc instanceof Locator)) { ! matchTopic((Locator)loc, ret); ! } else if ((topic instanceof Topic) && (loc instanceof Locator)) { ! closedMatch((Topic)topic, (Locator)loc, ret); ! } else if ((topic instanceof Variable) && (loc instanceof Variable)) { ! openMatch(ret); ! } ! return ret; ! } ! ! /** ! * @param ret ! */ ! private void openMatch(VariableSet ret) throws TologProcessingException { ! for (Iterator it = getTopicMap().getTopics().iterator(); it.hasNext();) { ! Topic topic = (Topic)it.next(); ! for (Iterator locIter = topic.getSubjectLocators().iterator(); locIter.hasNext();) { ! addResultsRow(ret, new Object[] { topic, locIter.next()}); ! } ! } ! } ! ! /** ! * @param topic ! * @param locator ! * @param ret ! */ ! private void closedMatch(Topic topic, Locator locator, VariableSet ret) throws TologProcessingException { ! if (topic.getSubjectLocators().contains(locator)) { ! addResultsRow(ret, new Object[] { topic, locator}); ! } ! } ! ! /** ! * @param locator ! * @param ret ! */ ! private void matchTopic(Locator locator, VariableSet ret) throws TologProcessingException { ! IndexUtils.updateIndex(_topicsIdx); ! Topic topic = _topicsIdx.getTopicBySubjectLocator(locator); ! if (topic != null) { ! addResultsRow(ret, new Object[] { topic, locator }); ! } ! } ! ! /** ! * @param topic ! * @param ret ! */ ! private void matchSubjectLocator(Topic topic, VariableSet ret) throws TologProcessingException { ! for (Iterator iter = topic.getSubjectLocators().iterator(); iter.hasNext();) { ! addResultsRow(ret, new Object[] { topic, iter.next()}); ! } ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.parser.Predicate#initialise(org.tmapi.core.TopicMap) ! */ ! public void initialise(TopicMap tm) throws TologParserException { ! super.initialise(tm); ! try { ! _topicsIdx = (TopicsIndex) tm.getHelperObject(TopicsIndex.class); ! } catch (TMAPIException ex) { ! throw new TologParserException("Unable to initialise indexes for " + PREDICATE_NAME, ex); ! } ! } ! ! } --- 1,142 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.predicates; ! ! import java.util.Iterator; ! import java.util.List; ! ! import org.tmapiutils.query.tolog.TologParserException; ! import org.tmapiutils.query.tolog.TologProcessingException; ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! ! import org.tmapiutils.utils.IndexUtils; ! // TMAPI ! import org.tmapi.core.Locator; ! import org.tmapi.core.TopicMap; ! import org.tmapi.core.Topic; ! import org.tmapi.core.TMAPIException; ! import org.tmapi.index.core.TopicsIndex; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class SubjectLocatorPredicate extends PredicateBase { ! ! private TopicsIndex _topicsIdx; ! public static final String PREDICATE_NAME = "subject-locator"; ! private static final ParameterInfo[] PARAM_INFO = new ParameterInfo[] { ! new ParameterInfo(true), ! new ParameterInfo(true) ! }; ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getParamInfo() ! */ ! public ParameterInfo[] getParamInfo() { ! return PARAM_INFO; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getPredicateName() ! */ ! public String getPredicateName() { ! return PREDICATE_NAME; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.parser.Predicate#matches(java.util.List) ! */ ! public VariableSet matches(List params) throws TologProcessingException { ! Object topic = params.get(0); ! Object loc = params.get(1); ! VariableSet ret = new VariableSet(); ! initialiseResultsSet(ret); ! ! if ((topic instanceof Topic) && (loc instanceof Variable)) { ! matchSubjectLocator((Topic)topic, ret); ! } else if ((topic instanceof Variable) && (loc instanceof Locator)) { ! matchTopic((Locator)loc, ret); ! } else if ((topic instanceof Topic) && (loc i... [truncated message content] |
Update of /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/utils In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30131/src/org/tmapiutils/query/tolog/utils Modified Files: DefaultRowComparator.java InvertedComparator.java ReferenceUtils.java RowComparator.java TologContext.java VariableSet.java Log Message: Tabs -> Whitespaces Index: InvertedComparator.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/utils/InvertedComparator.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** InvertedComparator.java 8 Mar 2005 12:34:00 -0000 1.2 --- InvertedComparator.java 8 Jul 2005 16:03:22 -0000 1.3 *************** *** 1,43 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.utils; ! ! import java.util.Comparator; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class InvertedComparator implements Comparator { ! ! Comparator m_comp; ! ! public InvertedComparator(Comparator comp) { ! m_comp = comp; ! } ! /* (non-Javadoc) ! * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) ! */ ! public int compare(Object o1, Object o2) { ! int c = m_comp.compare(o1, o2); ! return c * -1; ! } ! ! } ! --- 1,43 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.utils; ! ! import java.util.Comparator; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class InvertedComparator implements Comparator { ! ! Comparator m_comp; ! ! public InvertedComparator(Comparator comp) { ! m_comp = comp; ! } ! /* (non-Javadoc) ! * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) ! */ ! public int compare(Object o1, Object o2) { ! int c = m_comp.compare(o1, o2); ! return c * -1; ! } ! ! } ! Index: ReferenceUtils.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/utils/ReferenceUtils.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ReferenceUtils.java 8 Mar 2005 12:34:00 -0000 1.3 --- ReferenceUtils.java 8 Jul 2005 16:03:22 -0000 1.4 *************** *** 1,54 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.utils; ! ! import java.util.Iterator; ! ! import org.tmapi.core.Locator; ! import org.tmapi.core.TopicMapObject; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class ReferenceUtils ! { ! ! public static String getTologReference(TopicMapObject tmo) { ! String ret = null; ! Locator baseloc = tmo.getTopicMap().getBaseLocator(); ! String baseAddress = baseloc.getReference(); ! Iterator it = tmo.getSourceLocators().iterator(); ! while ((ret == null) && it.hasNext()) { ! Locator l = (Locator)it.next(); ! if (l.getReference().startsWith(baseAddress) && ! l.getReference().substring(baseAddress.length()).startsWith("#")) ! { ! ret = l.getReference().substring(baseAddress.length()); ! } ! } ! ! if (ret == null) { ! return "@" + tmo.getObjectId(); ! } else { ! return ret; ! } ! } ! } ! --- 1,54 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.utils; ! ! import java.util.Iterator; ! ! import org.tmapi.core.Locator; ! import org.tmapi.core.TopicMapObject; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class ReferenceUtils ! { ! ! public static String getTologReference(TopicMapObject tmo) { ! String ret = null; ! Locator baseloc = tmo.getTopicMap().getBaseLocator(); ! String baseAddress = baseloc.getReference(); ! Iterator it = tmo.getSourceLocators().iterator(); ! while ((ret == null) && it.hasNext()) { ! Locator l = (Locator)it.next(); ! if (l.getReference().startsWith(baseAddress) && ! l.getReference().substring(baseAddress.length()).startsWith("#")) ! { ! ret = l.getReference().substring(baseAddress.length()); ! } ! } ! ! if (ret == null) { ! return "@" + tmo.getObjectId(); ! } else { ! return ret; ! } ! } ! } ! Index: RowComparator.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/utils/RowComparator.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RowComparator.java 8 Mar 2005 12:34:00 -0000 1.2 --- RowComparator.java 8 Jul 2005 16:03:22 -0000 1.3 *************** *** 1,41 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.utils; ! ! import java.util.Comparator; ! import java.util.List; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public abstract class RowComparator implements Comparator { ! ! public abstract void addSortColumn(int ix); ! ! /* (non-Javadoc) ! * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) ! */ ! public int compare(Object o1, Object o2) { ! return compare((List)o1, (List)o2); ! } ! ! public abstract int compare(List row1, List row2); ! } ! --- 1,41 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.utils; ! ! import java.util.Comparator; ! import java.util.List; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public abstract class RowComparator implements Comparator { ! ! public abstract void addSortColumn(int ix); ! ! /* (non-Javadoc) ! * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) ! */ ! public int compare(Object o1, Object o2) { ! return compare((List)o1, (List)o2); ! } ! ! public abstract int compare(List row1, List row2); ! } ! Index: TologContext.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/utils/TologContext.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TologContext.java 8 Mar 2005 12:34:00 -0000 1.2 --- TologContext.java 8 Jul 2005 16:03:22 -0000 1.3 *************** *** 1,85 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.utils; ! ! import java.util.Iterator; ! import java.util.Stack; ! ! import org.tmapiutils.query.tolog.parser.TologRule; ! ! import java.util.List; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class TologContext { ! ! Stack m_ruleStack = new Stack(); ! ! public void pushRule(TologRule rule, List params) { ! if (rule.getName() == null) { ! throw new RuntimeException("Attempt to push unamed rule..."); ! } ! m_ruleStack.push(new TologContextElement(rule.getName(), params)); ! } ! ! public boolean inRule(TologRule rule) { ! Iterator it = m_ruleStack.iterator(); ! while (it.hasNext()) { ! TologContextElement e = (TologContextElement)it.next(); ! if (e.ruleName.equals(rule.getName())) { ! return true; ! } ! } ! return false; ! } ! ! public void popRule(TologRule rule) { ! if (((TologContextElement)m_ruleStack.peek()).ruleName.equals(rule.getName())) { ! m_ruleStack.pop(); ! } else { ! throw new RuntimeException("Tolog context rule stack got out of sync. Expected " + m_ruleStack.peek().toString() + " got " + rule.getName()); ! } ! } ! ! public List getParams(TologRule rule) { ! for (int i = m_ruleStack.size() - 1; i >= 0; i--) { ! TologContextElement e = (TologContextElement)m_ruleStack.get(i); ! if (e.ruleName.equals(rule.getName())) { ! return e.ruleParams; ! } ! } ! return null; ! } ! ! public int getDepth() { ! return m_ruleStack.size(); ! } ! ! class TologContextElement { ! String ruleName; ! List ruleParams; ! TologContextElement(String ruleName, List ruleParams) { ! this.ruleName = ruleName; ! this.ruleParams = ruleParams; ! } ! } ! } ! --- 1,85 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.utils; ! ! import java.util.Iterator; ! import java.util.Stack; ! ! import org.tmapiutils.query.tolog.parser.TologRule; ! ! import java.util.List; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class TologContext { ! ! Stack m_ruleStack = new Stack(); ! ! public void pushRule(TologRule rule, List params) { ! if (rule.getName() == null) { ! throw new RuntimeException("Attempt to push unamed rule..."); ! } ! m_ruleStack.push(new TologContextElement(rule.getName(), params)); ! } ! ! public boolean inRule(TologRule rule) { ! Iterator it = m_ruleStack.iterator(); ! while (it.hasNext()) { ! TologContextElement e = (TologContextElement)it.next(); ! if (e.ruleName.equals(rule.getName())) { ! return true; ! } ! } ! return false; ! } ! ! public void popRule(TologRule rule) { ! if (((TologContextElement)m_ruleStack.peek()).ruleName.equals(rule.getName())) { ! m_ruleStack.pop(); ! } else { ! throw new RuntimeException("Tolog context rule stack got out of sync. Expected " + m_ruleStack.peek().toString() + " got " + rule.getName()); ! } ! } ! ! public List getParams(TologRule rule) { ! for (int i = m_ruleStack.size() - 1; i >= 0; i--) { ! TologContextElement e = (TologContextElement)m_ruleStack.get(i); ! if (e.ruleName.equals(rule.getName())) { ! return e.ruleParams; ! } ! } ! return null; ! } ! ! public int getDepth() { ! return m_ruleStack.size(); ! } ! ! class TologContextElement { ! String ruleName; ! List ruleParams; ! TologContextElement(String ruleName, List ruleParams) { ! this.ruleName = ruleName; ! this.ruleParams = ruleParams; ! } ! } ! } ! Index: DefaultRowComparator.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/utils/DefaultRowComparator.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** DefaultRowComparator.java 8 Mar 2005 12:33:59 -0000 1.3 --- DefaultRowComparator.java 8 Jul 2005 16:03:22 -0000 1.4 *************** *** 1,76 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.utils; ! ! import java.util.ArrayList; ! import java.util.Iterator; ! import java.util.List; ! ! import org.tmapi.core.TopicName; ! import org.tmapi.core.TopicMapObject; ! ! /** ! * Simple default sorting algorithm. Compares the values in each sort column one at a time. ! * The following comparison algorithm is applied to each pair of values: ! * <ol> ! * <li>If the values are of different classes, then sort on class name</li> ! * <li>If the values implement Comparable, then invoke the compareTo method.</li> ! * <li>If the values implement TopicName, then compare on the base name string value.</li> ! * <li>If the values implement TopicMapObject, then compare on the ID property.</li> ! * </ol> ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class DefaultRowComparator extends RowComparator { ! ! private List m_sortColumns = new ArrayList(); ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.RowComparator#addSortColumn(int) ! */ ! public void addSortColumn(int ix) { ! m_sortColumns.add(new Integer(ix)); ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.RowComparator#compare(java.util.List, java.util.List) ! */ ! public int compare(List row1, List row2) { ! int ret = 0; ! Iterator cols = m_sortColumns.iterator(); ! while ((ret == 0) && (cols.hasNext())) { ! int ix = ((Integer)cols.next()).intValue(); ! Object o1 = row1.get(ix); ! Object o2 = row2.get(ix); ! ret = o1.getClass().getName().compareTo(o2.getClass().getName()); ! if (ret == 0) { ! if (o1 instanceof Comparable) { ! ret = ((Comparable)o1).compareTo(o2); ! } else if (o1 instanceof TopicName) { ! ret = ((TopicName)o1).getValue().compareTo(((TopicName)o2).getValue()); ! } else if (o1 instanceof TopicMapObject) { ! ret = ((TopicMapObject)o1).getObjectId().compareTo(((TopicMapObject)o2).getObjectId()); ! } ! } ! } ! return ret; ! } ! ! } ! --- 1,76 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.utils; ! ! import java.util.ArrayList; ! import java.util.Iterator; ! import java.util.List; ! ! import org.tmapi.core.TopicName; ! import org.tmapi.core.TopicMapObject; ! ! /** ! * Simple default sorting algorithm. Compares the values in each sort column one at a time. ! * The following comparison algorithm is applied to each pair of values: ! * <ol> ! * <li>If the values are of different classes, then sort on class name</li> ! * <li>If the values implement Comparable, then invoke the compareTo method.</li> ! * <li>If the values implement TopicName, then compare on the base name string value.</li> ! * <li>If the values implement TopicMapObject, then compare on the ID property.</li> ! * </ol> ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class DefaultRowComparator extends RowComparator { ! ! private List m_sortColumns = new ArrayList(); ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.RowComparator#addSortColumn(int) ! */ ! public void addSortColumn(int ix) { ! m_sortColumns.add(new Integer(ix)); ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.RowComparator#compare(java.util.List, java.util.List) ! */ ! public int compare(List row1, List row2) { ! int ret = 0; ! Iterator cols = m_sortColumns.iterator(); ! while ((ret == 0) && (cols.hasNext())) { ! int ix = ((Integer)cols.next()).intValue(); ! Object o1 = row1.get(ix); ! Object o2 = row2.get(ix); ! ret = o1.getClass().getName().compareTo(o2.getClass().getName()); ! if (ret == 0) { ! if (o1 instanceof Comparable) { ! ret = ((Comparable)o1).compareTo(o2); ! } else if (o1 instanceof TopicName) { ! ret = ((TopicName)o1).getValue().compareTo(((TopicName)o2).getValue()); ! } else if (o1 instanceof TopicMapObject) { ! ret = ((TopicMapObject)o1).getObjectId().compareTo(((TopicMapObject)o2).getObjectId()); ! } ! } ! } ! return ret; ! } ! ! } ! Index: VariableSet.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/utils/VariableSet.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** VariableSet.java 8 Mar 2005 12:34:00 -0000 1.3 --- VariableSet.java 8 Jul 2005 16:03:22 -0000 1.4 *************** *** 1,293 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.utils; ! ! import java.util.ArrayList; ! import java.util.Arrays; ! import java.util.Iterator; ! import java.util.List; ! import java.util.Map; ! ! import org.apache.commons.logging.Log; ! import org.tmapiutils.query.tolog.TologProcessingException; ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapi.core.TopicMapObject; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class VariableSet { ! ! private List m_rows; ! private List m_cols; ! ! public VariableSet() { ! m_rows = new ArrayList(); ! m_cols = new ArrayList(); ! } ! ! public int indexOf(Variable var) { ! return m_cols.indexOf(var); ! } ! ! public int addColumn(Object colHead) ! { ! int ix = m_cols.indexOf(colHead); ! if (ix > -1) { ! return ix; ! } ! m_cols.add(colHead); ! Iterator it = m_rows.iterator(); ! while (it.hasNext()) { ! ((List)it.next()).add(colHead); ! } ! return m_cols.size() - 1; ! } ! ! public void addRow(List values) throws TologProcessingException { ! if (values.size() != m_cols.size()) { ! throw new TologProcessingException("Row size is wrong. Expected " + m_cols.size() + " items. Got " + values.size() + " items."); ! } ! m_rows.add(values); ! } ! ! public void addRowFromMap(Map values) throws TologProcessingException { ! Iterator it = m_cols.iterator(); ! ArrayList newRow = new ArrayList(); ! while (it.hasNext()) { ! Object colHead = it.next(); ! Object val = values.get(colHead); ! if (val instanceof Variable) { ! val = values.get(val); ! } ! newRow.add(val == null ? colHead : val); ! } ! m_rows.add(newRow); ! } ! ! public List getColumn(Variable var) { ! ArrayList ret = new ArrayList(); ! int ix = indexOf(var); ! if (ix >= 0) { ! for (Iterator it = m_rows.iterator(); it.hasNext(); ) { ! ret.add(((List)it.next()).get(ix)); ! } ! } ! return ret; ! } ! ! /* ! public Map getMapping(int rowNum) { ! HashMap m = new HashMap(); ! List l = (List)m_rows.get(rowNum); ! for (int colNum = 0; colNum < m_cols.size(); colNum++) { ! Variable v = (Variable)m_cols.get(colNum); ! m.put(v, l.get(colNum)); ! } ! return Collections.unmodifiableMap(m); ! } ! */ ! public List removeRow(int rowNum) { ! return (List)m_rows.remove(rowNum); ! } ! ! public boolean isEmpty() { ! return m_rows.isEmpty(); ! } ! ! public List getColumns() { ! return m_cols; ! } ! ! public void addColumns(List vars) { ! m_cols.addAll(vars); ! Iterator newVars = vars.iterator(); ! while(newVars.hasNext()) { ! Variable v = (Variable)newVars.next(); ! Iterator it = m_rows.iterator(); ! while (it.hasNext()) { ! ((List)it.next()).add(v); ! } ! } ! } ! ! public Object clone() { ! VariableSet ret = new VariableSet(); ! ret.m_cols = new ArrayList(m_cols); ! ret.m_rows = new ArrayList(m_rows.size()); ! Iterator it = m_rows.iterator(); ! while (it.hasNext()) { ! List srcRow = (List)it.next(); ! ret.m_rows.add(new ArrayList(srcRow)); ! } ! return ret; ! } ! ! public int size() { ! return m_rows.size(); ! } ! ! ! public void dump(Log log) { ! if (log.isDebugEnabled()) { ! log.debug("Variable Set:" + toString()); ! log.debug(" column variables:" + dumpVars(m_cols)); ! int row = 1; ! for(Iterator it = m_rows.iterator();it.hasNext(); row++) { ! log.debug(" Row " + row + ":" + dumpRow((List)it.next())); ! } ! } ! } ! ! public void dump() { ! System.out.println("Variable Set:" + toString()); ! System.out.println(" column variables:" + dumpVars(m_cols)); ! int row = 1; ! for(Iterator it = m_rows.iterator();it.hasNext(); row++) { ! System.out.println(" Row " + row + ":" + dumpRow((List)it.next())); ! } ! } ! ! private String dumpVars(List l) { ! StringBuffer ret = new StringBuffer(); ! for (Iterator it = l.iterator();it.hasNext();) { ! ret.append(it.next().toString()); ! if (it.hasNext()) ret.append(", "); ! } ! return ret.toString(); ! } ! ! private String dumpRow(List r) { ! StringBuffer ret = new StringBuffer(); ! for (Iterator it = r.iterator(); it.hasNext();) { ! Object o = it.next(); ! if (o instanceof TopicMapObject) { ! ret.append(((TopicMapObject)o).getObjectId()); ! } else { ! ret.append(o.toString()); ! } ! if (it.hasNext()) ret.append(", "); ! } ! return ret.toString(); ! } ! ! public List project(Variable [] selectList, Variable countVar) { ! List ret = new ArrayList(); ! int[] selectIxs = new int[selectList.length]; ! for (int i = 0; i < selectList.length; i++) { ! selectIxs[i] = indexOf(selectList[i]); ! } ! Iterator it = m_rows.iterator(); ! while (it.hasNext()) { ! List srcRow = (List)it.next(); ! ArrayList projectRow = new ArrayList(selectList.length + 1); ! for (int i = 0; i < selectIxs.length; i++) { ! projectRow.add(srcRow.get(selectIxs[i])); ! } ! ! boolean add = true; ! Iterator retItems = ret.iterator(); ! while (retItems.hasNext()) { ! List l = (List)retItems.next(); ! if (l.subList(0, selectList.length).equals(projectRow)) { ! if (countVar != null) { ! Integer count = (Integer)l.get(selectList.length); ! l.set(selectList.length, new Integer(count.intValue() + 1)); ! } ! add = false; ! } ! } ! if (add) { ! if (countVar != null) { ! //HashSet countVals = new HashSet(); ! //countVals.add(m.get(countVar)); ! projectRow.add(new Integer(1)); ! } ! ret.add(projectRow); ! } ! } ! return ret; ! } ! ! /** ! * Adds one variable set to another, merging the columns ! * and duplicating column head values into empty cells. ! * @param v the variable set to be added to this one. ! * @throws TologProcessingException ! */ ! public void add(VariableSet v) throws TologProcessingException { ! if (v.m_cols.equals(m_cols)) { ! // Simplest case ! m_rows.addAll(v.m_rows); ! return; ! } ! int max = v.getColumns().size(); ! int [] colMap = new int[max]; ! for (int i = 0; i < max; i++) { ! colMap[i] = addColumn(v.getColumns().get(i)); ! } ! Iterator it = v.getRows().iterator(); ! while (it.hasNext()) { ! List srcRow = (List)it.next(); ! ArrayList newRow = new ArrayList(); ! newRow.addAll(m_cols); ! for (int i = 0; i < max; i++) { ! newRow.set(colMap[i], srcRow.get(i)); ! } ! m_rows.add(newRow); ! } ! } ! ! /** ! * @param objects ! */ ! public void addRow(Object[] values) throws TologProcessingException { ! ArrayList row = new ArrayList(); ! row.addAll(Arrays.asList(values)); ! addRow(row); ! } ! ! public List getRows() { ! return m_rows; ! } ! ! public List getRow(int ix) { ! return (List)m_rows.get(ix); ! } ! ! public void addMatchResults(List inputRow, VariableSet results) { ! Iterator rows = results.getRows().iterator(); ! while (rows.hasNext()) { ! List rowToAdd = new ArrayList(); ! List resultRow = (List)rows.next(); ! rowToAdd.addAll(inputRow); ! List cols = results.getColumns(); ! int max = cols.size(); ! for (int c = 0; c < max; c++) { ! if (cols.get(c) instanceof Variable) { ! int ix = indexOf((Variable)cols.get(c)); ! rowToAdd.set(ix, resultRow.get(c)); ! } ! } ! m_rows.add(rowToAdd); ! } ! } ! } ! --- 1,293 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.utils; ! ! import java.util.ArrayList; ! import java.util.Arrays; ! import java.util.Iterator; ! import java.util.List; ! import java.util.Map; ! ! import org.apache.commons.logging.Log; ! import org.tmapiutils.query.tolog.TologProcessingException; ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapi.core.TopicMapObject; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class VariableSet { ! ! private List m_rows; ! private List m_cols; ! ! public VariableSet() { ! m_rows = new ArrayList(); ! m_cols = new ArrayList(); ! } ! ! public int indexOf(Variable var) { ! return m_cols.indexOf(var); ! } ! ! public int addColumn(Object colHead) ! { ! int ix = m_cols.indexOf(colHead); ! if (ix > -1) { ! return ix; ! } ! m_cols.add(colHead); ! Iterator it = m_rows.iterator(); ! while (it.hasNext()) { ! ((List)it.next()).add(colHead); ! } ! return m_cols.size() - 1; ! } ! ! public void addRow(List values) throws TologProcessingException { ! if (values.size() != m_cols.size()) { ! throw new TologProcessingException("Row size is wrong. Expected " + m_cols.size() + " items. Got " + values.size() + " items."); ! } ! m_rows.add(values); ! } ! ! public void addRowFromMap(Map values) throws TologProcessingException { ! Iterator it = m_cols.iterator(); ! ArrayList newRow = new ArrayList(); ! while (it.hasNext()) { ! Object colHead = it.next(); ! Object val = values.get(colHead); ! if (val instanceof Variable) { ! val = values.get(val); ! } ! newRow.add(val == null ? colHead : val); ! } ! m_rows.add(newRow); ! } ! ! public List getColumn(Variable var) { ! ArrayList ret = new ArrayList(); ! int ix = indexOf(var); ! if (ix >= 0) { ! for (Iterator it = m_rows.iterator(); it.hasNext(); ) { ! ret.add(((List)it.next()).get(ix)); ! } ! } ! return ret; ! } ! ! /* ! public Map getMapping(int rowNum) { ! HashMap m = new HashMap(); ! List l = (List)m_rows.get(rowNum); ! for (int colNum = 0; colNum < m_cols.size(); colNum++) { ! Variable v = (Variable)m_cols.get(colNum); ! m.put(v, l.get(colNum)); ! } ! return Collections.unmodifiableMap(m); ! } ! */ ! public List removeRow(int rowNum) { ! return (List)m_rows.remove(rowNum); ! } ! ! public boolean isEmpty() { ! return m_rows.isEmpty(); ! } ! ! public List getColumns() { ! return m_cols; ! } ! ! public void addColumns(List vars) { ! m_cols.addAll(vars); ! Iterator newVars = vars.iterator(); ! while(newVars.hasNext()) { ! Variable v = (Variable)newVars.next(); ! Iterator it = m_rows.iterator(); ! while (it.hasNext()) { ! ((List)it.next()).add(v); ! } ! } ! } ! ! public Object clone() { ! VariableSet ret = new VariableSet(); ! ret.m_cols = new ArrayList(m_cols); ! ret.m_rows = new ArrayList(m_rows.size()); ! Iterator it = m_rows.iterator(); ! while (it.hasNext()) { ! List srcRow = (List)it.next(); ! ret.m_rows.add(new ArrayList(srcRow)); ! } ! return ret; ! } ! ! public int size() { ! return m_rows.size(); ! } ! ! ! public void dump(Log log) { ! if (log.isDebugEnabled()) { ! log.debug("Variable Set:" + toString()); ! log.debug(" column variables:" + dumpVars(m_cols)); ! int row = 1; ! for(Iterator it = m_rows.iterator();it.hasNext(); row++) { ! log.debug(" Row " + row + ":" + dumpRow((List)it.next())); ! } ! } ! } ! ! public void dump() { ! System.out.println("Variable Set:" + toString()); ! System.out.println(" column variables:" + dumpVars(m_cols)); ! int row = 1; ! for(Iterator it = m_rows.iterator();it.hasNext(); row++) { ! System.out.println(" Row " + row + ":" + dumpRow((List)it.next())); ! } ! } ! ! private String dumpVars(List l) { ! StringBuffer ret = new StringBuffer(); ! for (Iterator it = l.iterator();it.hasNext();) { ! ret.append(it.next().toString()); ! if (it.hasNext()) ret.append(", "); ! } ! return ret.toString(); ! } ! ! private String dumpRow(List r) { ! StringBuffer ret = new StringBuffer(); ! for (Iterator it = r.iterator(); it.hasNext();) { ! Object o = it.next(); ! if (o instanceof TopicMapObject) { ! ret.append(((TopicMapObject)o).getObjectId()); ! } else { ! ret.append(o.toString()); ! } ! if (it.hasNext()) ret.append(", "); ! } ! return ret.toString(); ! } ! ! public List project(Variable [] selectList, Variable countVar) { ! List ret = new ArrayList(); ! int[] selectIxs = new int[selectList.length]; ! for (int i = 0; i < selectList.length; i++) { ! selectIxs[i] = indexOf(selectList[i]); ! } ! Iterator it = m_rows.iterator(); ! while (it.hasNext()) { ! List srcRow = (List)it.next(); ! ArrayList projectRow = new ArrayList(selectList.length + 1); ! for (int i = 0; i < selectIxs.length; i++) { ! projectRow.add(srcRow.get(selectIxs[i])); ! } ! ! boolean add = true; ! Iterator retItems = ret.iterator(); ! while (retItems.hasNext()) { ! List l = (List)retItems.next(); ! if (l.subList(0, selectList.length).equals(projectRow)) { ! if (countVar != null) { ! Integer count = (Integer)l.get(selectList.length); ! l.set(selectList.length, new Integer(count.intValue() + 1)); ! } ! add = false; ! } ! } ! if (add) { ! if (countVar != null) { ! //HashSet countVals = new HashSet(); ! //countVals.add(m.get(countVar)); ! projectRow.add(new Integer(1)); ! } ! ret.add(projectRow); ! } ! } ! return ret; ! } ! ! /** ! * Adds one variable set to another, merging the columns ! * and duplicating column head values into empty cells. ! * @param v the variable set to be added to this one. ! * @throws TologProcessingException ! */ ! public void add(VariableSet v) throws TologProcessingException { ! if (v.m_cols.equals(m_cols)) { ! // Simplest case ! m_rows.addAll(v.m_rows); ! return; ! } ! int max = v.getColumns().size(); ! int [] colMap = new int[max]; ! for (int i = 0; i < max; i++) { ! colMap[i] = addColumn(v.getColumns().get(i)); ! } ! Iterator it = v.getRows().iterator(); ! while (it.hasNext()) { ! List srcRow = (List)it.next(); ! ArrayList newRow = new ArrayList(); ! newRow.addAll(m_cols); ! for (int i = 0; i < max; i++) { ! newRow.set(colMap[i], srcRow.get(i)); ! } ! m_rows.add(newRow); ! } ! } ! ! /** ! * @param objects ! */ ! public void addRow(Object[] values) throws TologProcessingException { ! ArrayList row = new ArrayList(); ! row.addAll(Arrays.asList(values)); ! addRow(row); ! } ! ! public List getRows() { ! return m_rows; ! } ! ! public List getRow(int ix) { ! return (List)m_rows.get(ix); ! } ! ! public void addMatchResults(List inputRow, VariableSet results) { ! Iterator rows = results.getRows().iterator(); ! while (rows.hasNext()) { ! List rowToAdd = new ArrayList(); ! List resultRow = (List)rows.next(); ! rowToAdd.addAll(inputRow); ! List cols = results.getColumns(); ! int max = cols.size(); ! for (int c = 0; c < max; c++) { ! if (cols.get(c) instanceof Variable) { ! int ix = indexOf((Variable)cols.get(c)); ! rowToAdd.set(ix, resultRow.get(c)); ! } ! } ! m_rows.add(rowToAdd); ! } ! } ! } ! |
From: Lars H. <lh...@us...> - 2005-07-08 16:03:32
|
Update of /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/test/backends In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30131/src/org/tmapiutils/query/tolog/test/backends Modified Files: BasicTests.java QueryTestBase.java Log Message: Tabs -> Whitespaces Index: QueryTestBase.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/test/backends/QueryTestBase.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** QueryTestBase.java 8 Mar 2005 12:33:59 -0000 1.3 --- QueryTestBase.java 8 Jul 2005 16:03:21 -0000 1.4 *************** *** 1,173 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.test.backends; ! ! import java.io.File; ! import java.io.FileInputStream; ! import java.util.HashMap; ! import java.util.Iterator; ! import java.util.List; ! ! import org.tmapi.core.Locator; ! import org.tm4j.test.ConfigurableBackendTest; ! import org.tmapiutils.query.tolog.TologResultsSet; ! import org.tmapiutils.query.tolog.QueryEvaluator; ! import org.tmapiutils.query.tolog.QueryEvaluatorFactory; ! import org.tmapi.core.Topic; ! import org.tmapi.core.TopicMap; ! import org.tmapi.core.TopicMapObject; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class QueryTestBase extends ConfigurableBackendTest ! { ! private HashMap m_maps; ! ! public QueryTestBase(String name) { ! super(name); ! m_maps = new HashMap(); ! } ! ! public TopicMap getTopicMap(String tmKey) throws Exception ! { ! TopicMap ret = (TopicMap) m_maps.get(tmKey); ! if (ret == null) { ! ret = super.getTopicMap(tmKey); ! m_maps.put(tmKey, ret); ! } ! return ret; ! } ! ! protected void doQueryWithModule(TopicMap tm, File moduleFile, String modulePrefix, String queryString, String[][] expectedResults) throws Exception { ! QueryEvaluator qe = QueryEvaluatorFactory.newQueryEvaluator(tm); ! qe.addRulesModule(new FileInputStream(moduleFile), modulePrefix); ! TologResultsSet rs = qe.execute(queryString); ! validateResultsSet(rs, expectedResults); ! } ! ! protected void doQuery(TopicMap tm, String queryString, String[][] expectedResults) throws Exception { ! QueryEvaluator qe = QueryEvaluatorFactory.newQueryEvaluator(tm); ! TologResultsSet rs = qe.execute(queryString); ! validateResultsSet(rs, expectedResults); ! } ! ! protected void doQuery(TopicMap tm, String [] rules, String queryString, String [][] expectedResults) throws Exception { ! QueryEvaluator qe = QueryEvaluatorFactory.newQueryEvaluator(tm); ! for (int i = 0; i < rules.length; i++) { ! qe.addRule(rules[i]); ! } ! TologResultsSet rs = qe.execute(queryString); ! validateResultsSet(rs, expectedResults); ! } ! ! protected void validateResultsSet(TologResultsSet rs, String[][] expectedResults) throws Exception { ! assertEquals("Results set size is wrong.", expectedResults.length, rs.getNumRows()); ! for (int i = 0; i < rs.getNumRows(); i++) { ! if (!validateRow(rs.getRow(i), expectedResults)) { ! fail("No match found for row " + i + " in results set. Got: " + dumpRow(rs.getRow(i))); ! } ! } ! } ! ! public String dumpResultsSet(TologResultsSet rs) { ! StringBuffer ret = new StringBuffer(); ! for (int i =0; i < rs.getNumRows(); i++) { ! ret.append(dumpRow(rs.getRow(i))); ! ret.append("\n"); ! } ! return ret.toString(); ! } ! ! /** ! * @param list ! * @return ! */ ! private String dumpRow(List row) { ! StringBuffer ret = new StringBuffer(); ! Iterator it = row.iterator(); ! while (it.hasNext()) { ! Object o = (Object)it.next(); ! if (o instanceof Topic) { ! ret.append(((Topic)o).getObjectId()); ! } else { ! ret.append(o.getClass().getName() + ": " + o.toString()); ! } ! if (it.hasNext()) ret.append(", "); ! } ! return ret.toString(); ! } ! ! protected boolean validateRow(List row, String[][]expected) throws Exception { ! for (int i = 0; i < expected.length; i++) { ! if (validateRow(row, expected[i])) { ! return true; ! } ! } ! return false; ! } ! ! protected boolean validateRow(List row, String [] expected) throws Exception { ! if (row.size() != expected.length) return false; ! for (int i = 0; i < row.size(); i++) { ! Object o = row.get(i); ! String exp = expected[i]; ! boolean v = false; ! if (o instanceof TopicMapObject) { ! v = validate((TopicMapObject)o, exp); ! } else if (o instanceof Locator) { ! v = validate((Locator)o, exp); ! } else if (o instanceof String) { ! v = o.equals(exp); ! } ! if (!v) return false; ! } ! return true; ! } ! ! /** ! * @param locator ! * @param expected ! * @return ! */ ! private boolean validate(Locator locator, String expected) { ! return locator.getReference().equals(expected); ! } ! ! /** ! * @param topic ! * @param expected ! * @return ! */ ! private boolean validate(TopicMapObject tmo, String expected) throws Exception ! { ! if (tmo.getObjectId().equals(expected)) { ! return true; ! } else { ! Locator loc = tmo.getTopicMap().getBaseLocator().resolveRelative("#" + expected); ! Iterator it = tmo.getSourceLocators().iterator(); ! while (it.hasNext()) { ! if (((Locator)it.next()).getReference().equals(expected)) return true; ! } ! } ! return false; ! } ! } ! --- 1,173 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.test.backends; ! ! import java.io.File; ! import java.io.FileInputStream; ! import java.util.HashMap; ! import java.util.Iterator; ! import java.util.List; ! ! import org.tmapi.core.Locator; ! import org.tm4j.test.ConfigurableBackendTest; ! import org.tmapiutils.query.tolog.TologResultsSet; ! import org.tmapiutils.query.tolog.QueryEvaluator; ! import org.tmapiutils.query.tolog.QueryEvaluatorFactory; ! import org.tmapi.core.Topic; ! import org.tmapi.core.TopicMap; ! import org.tmapi.core.TopicMapObject; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class QueryTestBase extends ConfigurableBackendTest ! { ! private HashMap m_maps; ! ! public QueryTestBase(String name) { ! super(name); ! m_maps = new HashMap(); ! } ! ! public TopicMap getTopicMap(String tmKey) throws Exception ! { ! TopicMap ret = (TopicMap) m_maps.get(tmKey); ! if (ret == null) { ! ret = super.getTopicMap(tmKey); ! m_maps.put(tmKey, ret); ! } ! return ret; ! } ! ! protected void doQueryWithModule(TopicMap tm, File moduleFile, String modulePrefix, String queryString, String[][] expectedResults) throws Exception { ! QueryEvaluator qe = QueryEvaluatorFactory.newQueryEvaluator(tm); ! qe.addRulesModule(new FileInputStream(moduleFile), modulePrefix); ! TologResultsSet rs = qe.execute(queryString); ! validateResultsSet(rs, expectedResults); ! } ! ! protected void doQuery(TopicMap tm, String queryString, String[][] expectedResults) throws Exception { ! QueryEvaluator qe = QueryEvaluatorFactory.newQueryEvaluator(tm); ! TologResultsSet rs = qe.execute(queryString); ! validateResultsSet(rs, expectedResults); ! } ! ! protected void doQuery(TopicMap tm, String [] rules, String queryString, String [][] expectedResults) throws Exception { ! QueryEvaluator qe = QueryEvaluatorFactory.newQueryEvaluator(tm); ! for (int i = 0; i < rules.length; i++) { ! qe.addRule(rules[i]); ! } ! TologResultsSet rs = qe.execute(queryString); ! validateResultsSet(rs, expectedResults); ! } ! ! protected void validateResultsSet(TologResultsSet rs, String[][] expectedResults) throws Exception { ! assertEquals("Results set size is wrong.", expectedResults.length, rs.getNumRows()); ! for (int i = 0; i < rs.getNumRows(); i++) { ! if (!validateRow(rs.getRow(i), expectedResults)) { ! fail("No match found for row " + i + " in results set. Got: " + dumpRow(rs.getRow(i))); ! } ! } ! } ! ! public String dumpResultsSet(TologResultsSet rs) { ! StringBuffer ret = new StringBuffer(); ! for (int i =0; i < rs.getNumRows(); i++) { ! ret.append(dumpRow(rs.getRow(i))); ! ret.append("\n"); ! } ! return ret.toString(); ! } ! ! /** ! * @param list ! * @return ! */ ! private String dumpRow(List row) { ! StringBuffer ret = new StringBuffer(); ! Iterator it = row.iterator(); ! while (it.hasNext()) { ! Object o = (Object)it.next(); ! if (o instanceof Topic) { ! ret.append(((Topic)o).getObjectId()); ! } else { ! ret.append(o.getClass().getName() + ": " + o.toString()); ! } ! if (it.hasNext()) ret.append(", "); ! } ! return ret.toString(); ! } ! ! protected boolean validateRow(List row, String[][]expected) throws Exception { ! for (int i = 0; i < expected.length; i++) { ! if (validateRow(row, expected[i])) { ! return true; ! } ! } ! return false; ! } ! ! protected boolean validateRow(List row, String [] expected) throws Exception { ! if (row.size() != expected.length) return false; ! for (int i = 0; i < row.size(); i++) { ! Object o = row.get(i); ! String exp = expected[i]; ! boolean v = false; ! if (o instanceof TopicMapObject) { ! v = validate((TopicMapObject)o, exp); ! } else if (o instanceof Locator) { ! v = validate((Locator)o, exp); ! } else if (o instanceof String) { ! v = o.equals(exp); ! } ! if (!v) return false; ! } ! return true; ! } ! ! /** ! * @param locator ! * @param expected ! * @return ! */ ! private boolean validate(Locator locator, String expected) { ! return locator.getReference().equals(expected); ! } ! ! /** ! * @param topic ! * @param expected ! * @return ! */ ! private boolean validate(TopicMapObject tmo, String expected) throws Exception ! { ! if (tmo.getObjectId().equals(expected)) { ! return true; ! } else { ! Locator loc = tmo.getTopicMap().getBaseLocator().resolveRelative("#" + expected); ! Iterator it = tmo.getSourceLocators().iterator(); ! while (it.hasNext()) { ! if (((Locator)it.next()).getReference().equals(expected)) return true; ! } ! } ! return false; ! } ! } ! Index: BasicTests.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/test/backends/BasicTests.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** BasicTests.java 8 Mar 2005 12:33:59 -0000 1.2 --- BasicTests.java 8 Jul 2005 16:03:21 -0000 1.3 *************** *** 1,265 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.test.backends; ! ! import org.tmapiutils.query.tolog.QueryEvaluator; ! import org.tmapiutils.query.tolog.QueryEvaluatorFactory; ! import org.tmapiutils.query.tolog.TologResultsSet; ! import org.tmapi.core.TopicMap; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class BasicTests extends QueryTestBase ! { ! ! /** ! * @param name ! */ ! public BasicTests(String name) { ! super(name); ! } ! ! public void testOneDynamicAssociation() throws Exception ! { ! TopicMap tm = getTopicMap("tolog.blocks"); ! assertNotNull(tm); ! doQuery(tm, "select $A from has-shape($A:block, cylinder:shape)?", ! new String [][] { ! new String[] { "blueblock" } ! }); ! } ! ! public void testOpenDynamicAssociation() throws Exception ! { ! doQuery( ! getTopicMap("tolog.blocks"), ! "select $A, $B from restson($A:upper, $B:lower) ?", ! new String [][] { ! new String [] { "redblock", "blueblock" }, ! new String [] { "redblock", "greenblock"}, ! new String [] { "yellowblock", "redblock"}}); ! } ! ! public void testTwoDynamicAssociationsAND() throws Exception ! { ! doQuery( ! getTopicMap("tolog.blocks"), ! "select $A from restson($A:upper, $B:lower), has-shape($B:block, cylinder:shape) ?", ! new String [][] { ! new String[] { "redblock" } ! }); ! } ! ! public void testTwoDynamicAssociationsOR() throws Exception ! { ! doQuery( ! getTopicMap("tolog.blocks"), ! "select $A from { restson($A:upper, redblock:lower) | has-shape($A:block, cylinder:shape) }?", ! new String [][] { ! new String [] { "yellowblock" }, ! new String [] { "blueblock" } ! }); ! } ! ! public void testInstanceOf() throws Exception ! { ! doQuery( ! getTopicMap("tolog.blocks"), ! "select $A from instance-of($A, block) ?", ! new String [][] { ! new String [] {"blueblock"}, ! new String [] {"greenblock"}, ! new String [] {"redblock"}, ! new String [] {"yellowblock"}}); ! ! doQuery( ! getTopicMap("tolog.blocks"), ! "select $A from instance-of($A, block), has-shape($A:block, cylinder:shape) ?", ! new String [][] { ! new String [] {"blueblock"}}); ! } ! ! public void testNamesToValues() throws Exception { ! doQuery( ! getTopicMap("tolog.blocks"), ! "select $BLOCK, $NAMEVAL from instance-of($BLOCK, block), topic-name($BLOCK, $NAME), value($NAME, $NAMEVAL) ?", ! new String [][] { ! new String [] {"blueblock", "Blue Block"}, ! new String [] {"greenblock", "Green Block"}, ! new String [] {"redblock", "Red Block"}, ! new String [] {"yellowblock", "Yellow Block"}}); ! } ! ! public void testNamesAndOcurrencesToValues() throws Exception { ! doQuery( ! getTopicMap("tolog.blocks"), ! "select $BLOCK, $NAMEVAL, $WEIGHTVAL from " + "instance-of($BLOCK, block), topic-name($BLOCK, $NAME), occurrence($BLOCK, $OCC)," + "type($OCC, weight-g), " + "value($NAME, $NAMEVAL), value($OCC, $WEIGHTVAL) ?", ! new String [][] { ! new String [] {"blueblock", "Blue Block", "20"}, ! new String [] {"greenblock", "Green Block", "5"}, ! new String [] {"redblock", "Red Block", "10"}, ! new String [] {"yellowblock", "Yellow Block", "15"}}); ! ! } ! ! public void testDynamicAssociationWithVariableType() throws Exception { ! doQuery( ! getTopicMap("tolog.blocks"), ! "select $ASSOC, $OTHER from $ASSOC(redblock, $OTHER), $OTHER /= redblock ?", ! new String[][] { ! new String[] {"restson", "blueblock"}, ! new String[] {"restson", "greenblock"}, ! new String[] {"has-shape", "rectangle"}, ! new String[] {"restson", "yellowblock"} ! }); ! } ! ! private static final String [] auto_rules = new String [] { ! "matches-facet($FACET, $FV, $INST) :- " + ! " { classified-as($INST : instance, $FV:classification)" + ! " |" + ! " facet-has-hierarchy-type($FACET : facet, $ASSOC:facet-hierarchy-type)," + ! " direct-instance-of($SUPER, superordinate-role)," + ! " direct-instance-of($SUB, subordinate-role)," + ! " $ASSOC($FV:$SUPER, $X:$SUB)," + ! " matches-facet($FACET, $X, $INST)" + ! "}.", ! ! "subfacet-of($SUBFV, $SUPERFV, $FACET) :- " + ! " facet-has-hierarchy-type($FACET : facet, $ASSOC : facet-hierarchy-type)," + ! " direct-instance-of($SUPER, superordinate-role)," + ! " direct-instance-of($SUB, subordinate-role)," + ! " { $ASSOC($SUBFV : $SUB, $SUPERFV : $SUPER) " + ! " |" + ! " $ASSOC($SUBFV : $SUB, $X : $SUPER)," + ! " subfacet-of($X, $SUPERFV, $FACET)" + ! " }.", ! ! "direct-subfacet-of($SUBFV, $SUPERFV, $FACET) :- " + ! " facet-has-hierarchy-type($FACET:facet, $ASSOC:facet-hierarchy-type)," + ! " direct-instance-of($SUPER, superordinate-role)," + ! " direct-instance-of($SUB, subordinate-role)," + ! " $ASSOC($SUBFV:$SUB, $SUPERFV:$SUPER).", ! ! }; ! ! public void testRecursiveRules() throws Exception { ! doQuery( ! getTopicMap("tolog.facets"), ! auto_rules, ! "select $AUTO from matches-facet(body-type, hatchback, $AUTO) ?", ! new String[][] { ! new String [] {"clio1_2"}, ! new String [] {"astra1_2"}, ! new String [] {"peugot206"}, ! new String [] {"peugot307"}, ! }); ! } ! ! public void testRecursiveRulesList() throws Exception { ! doQuery( ! getTopicMap("tolog.facets"), ! auto_rules, ! "select $INST from matches-facet(body-type,hatchback,$INST), matches-facet(engine-type,petrol,$INST) ?", ! new String[][] { ! new String [] {"clio1_2"}, ! new String [] {"astra1_2"}, ! new String [] {"peugot206"}, ! }); ! } ! ! public void testRecursiveRulesList2() throws Exception { ! TopicMap tm = getTopicMap("tolog.facets"); ! QueryEvaluator qe = QueryEvaluatorFactory.newQueryEvaluator(tm); ! for (int i = 0; i < auto_rules.length; i++) { ! qe.addRule(auto_rules[i]); ! } ! TologResultsSet rs = null; ! rs = qe.execute("select $SUB from direct-subfacet-of($SUB, all-body-types, body-type) ?"); ! assertEquals(5, rs.getNumRows()); ! rs = qe.execute("select $S from subfacet-of($S, all-body-types, body-type) ?"); ! assertEquals(8, rs.getNumRows()); ! rs = qe.execute("select $AUTO from matches-facet(body-type, all-body-types, $AUTO) ?"); ! assertEquals(7, rs.getNumRows()); ! rs = qe.execute("select $AUTO from matches-facet(engine-type, all-engine-types, $AUTO) ?"); ! assertEquals(7, rs.getNumRows()); ! rs = qe.execute("select $AUTO from matches-facet(engine-size, all-engine-sizes, $AUTO) ?"); ! assertEquals(7, rs.getNumRows()); ! rs = qe.execute("select $AUTO from matches-facet(body-type, all-body-types, $AUTO), matches-facet(engine-type, all-engine-types, $AUTO), matches-facet(engine-size, all-engine-sizes, $AUTO) ?"); ! assertEquals(7, rs.getNumRows()); ! this.validateResultsSet(rs, ! new String[][] { ! new String [] {"clio1_2"}, ! new String [] {"astra1_2"}, ! new String [] {"peugot206"}, ! new String [] {"peugot307"}, ! new String [] {"almera1_8"}, ! new String [] {"zafira2_0"}, ! new String [] {"frontera2_2"}}); ! } ! ! public void testRuleWithNoMatch() throws Exception { ! TopicMap tm = getTopicMap("tolog.facets"); ! QueryEvaluator qe = QueryEvaluatorFactory.newQueryEvaluator(tm); ! qe.addRule( ! "direct-subfacet-of($SUBFV, $SUPERFV, $FACET) :- " + ! "facet-has-hierarchy-type($FACET:facet, $ASSOC:facet-hierarchy-type)," + ! "$ASSOC($SUBFV:$SUB, $SUPERFV:$SUPER)," + ! "direct-instance-of($SUPER, superordinate-role)," + ! "direct-instance-of($SUB, subordinate-role)."); ! qe.addRule( ! "subfacet-of($SUBFV, $SUPERFV, $FACET) :- " + ! "{ direct-subfacet-of($SUBFV, $X, $FACET), subfacet-of($X, $SUPERFV, $FACET) " + ! " | direct-subfacet-of($SUBFV, $SUPERFV, $FACET) }."); ! qe.addRule( ! "matches-facet($FACET, $FV, $INST) :- " + ! "{ subfacet-of($C,$FV,$FACET), classified-as($INST:instance, $C:classification)" + ! " | classified-as($INST:instance, $FV:classification) }."); ! TologResultsSet rs = null; ! rs = qe.execute("select $CHILD from direct-subfacet-of($CHILD, @petrol, @engine-type) ?"); ! dumpResultsSet(rs); ! assertEquals(0, rs.getNumRows()); ! } ! ! public void testReifiesPredicate() throws Exception { ! TopicMap tm = getTopicMap("tolog.reification"); ! /* ! doQuery( ! tm, ! "select $REIFIER from reifies($REIFIER, a1) ?", ! new String[][] { ! new String [] {"re-a1"}, ! }); ! */ ! doQuery( ! tm, ! "select $REIFIED from reifies(re-a1, $REIFIED) ?", ! new String[][] { ! new String [] {"a1"}, ! }); ! doQuery( ! tm, "select $REIFIER, $REIFIED from reifies($REIFIER, $REIFIED) ?", ! new String [][] { ! new String [] {"re-a1", "a1"} ! }); ! } ! } ! --- 1,265 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.test.backends; ! ! import org.tmapiutils.query.tolog.QueryEvaluator; ! import org.tmapiutils.query.tolog.QueryEvaluatorFactory; ! import org.tmapiutils.query.tolog.TologResultsSet; ! import org.tmapi.core.TopicMap; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class BasicTests extends QueryTestBase ! { ! ! /** ! * @param name ! */ ! public BasicTests(String name) { ! super(name); ! } ! ! public void testOneDynamicAssociation() throws Exception ! { ! TopicMap tm = getTopicMap("tolog.blocks"); ! assertNotNull(tm); ! doQuery(tm, "select $A from has-shape($A:block, cylinder:shape)?", ! new String [][] { ! new String[] { "blueblock" } ! }); ! } ! ! public void testOpenDynamicAssociation() throws Exception ! { ! doQuery( ! getTopicMap("tolog.blocks"), ! "select $A, $B from restson($A:upper, $B:lower) ?", ! new String [][] { ! new String [] { "redblock", "blueblock" }, ! new String [] { "redblock", "greenblock"}, ! new String [] { "yellowblock", "redblock"}}); ! } ! ! public void testTwoDynamicAssociationsAND() throws Exception ! { ! doQuery( ! getTopicMap("tolog.blocks"), ! "select $A from restson($A:upper, $B:lower), has-shape($B:block, cylinder:shape) ?", ! new String [][] { ! new String[] { "redblock" } ! }); ! } ! ! public void testTwoDynamicAssociationsOR() throws Exception ! { ! doQuery( ! getTopicMap("tolog.blocks"), ! "select $A from { restson($A:upper, redblock:lower) | has-shape($A:block, cylinder:shape) }?", ! new String [][] { ! new String [] { "yellowblock" }, ! new String [] { "blueblock" } ! }); ! } ! ! public void testInstanceOf() throws Exception ! { ! doQuery( ! getTopicMap("tolog.blocks"), ! "select $A from instance-of($A, block) ?", ! new String [][] { ! new String [] {"blueblock"}, ! new String [] {"greenblock"}, ! new String [] {"redblock"}, ! new String [] {"yellowblock"}}); ! ! doQuery( ! getTopicMap("tolog.blocks"), ! "select $A from instance-of($A, block), has-shape($A:block, cylinder:shape) ?", ! new String [][] { ! new String [] {"blueblock"}}); ! } ! ! public void testNamesToValues() throws Exception { ! doQuery( ! getTopicMap("tolog.blocks"), ! "select $BLOCK, $NAMEVAL from instance-of($BLOCK, block), topic-name($BLOCK, $NAME), value($NAME, $NAMEVAL) ?", ! new String [][] { ! new String [] {"blueblock", "Blue Block"}, ! new String [] {"greenblock", "Green Block"}, ! new String [] {"redblock", "Red Block"}, ! new String [] {"yellowblock", "Yellow Block"}}); ! } ! ! public void testNamesAndOcurrencesToValues() throws Exception { ! doQuery( ! getTopicMap("tolog.blocks"), ! "select $BLOCK, $NAMEVAL, $WEIGHTVAL from " + "instance-of($BLOCK, block), topic-name($BLOCK, $NAME), occurrence($BLOCK, $OCC)," + "type($OCC, weight-g), " + "value($NAME, $NAMEVAL), value($OCC, $WEIGHTVAL) ?", ! new String [][] { ! new String [] {"blueblock", "Blue Block", "20"}, ! new String [] {"greenblock", "Green Block", "5"}, ! new String [] {"redblock", "Red Block", "10"}, ! new String [] {"yellowblock", "Yellow Block", "15"}}); ! ! } ! ! public void testDynamicAssociationWithVariableType() throws Exception { ! doQuery( ! getTopicMap("tolog.blocks"), ! "select $ASSOC, $OTHER from $ASSOC(redblock, $OTHER), $OTHER /= redblock ?", ! new String[][] { ! new String[] {"restson", "blueblock"}, ! new String[] {"restson", "greenblock"}, ! new String[] {"has-shape", "rectangle"}, ! new String[] {"restson", "yellowblock"} ! }); ! } ! ! private static final String [] auto_rules = new String [] { ! "matches-facet($FACET, $FV, $INST) :- " + ! " { classified-as($INST : instance, $FV:classification)" + ! " |" + ! " facet-has-hierarchy-type($FACET : facet, $ASSOC:facet-hierarchy-type)," + ! " direct-instance-of($SUPER, superordinate-role)," + ! " direct-instance-of($SUB, subordinate-role)," + ! " $ASSOC($FV:$SUPER, $X:$SUB)," + ! " matches-facet($FACET, $X, $INST)" + ! "}.", ! ! "subfacet-of($SUBFV, $SUPERFV, $FACET) :- " + ! " facet-has-hierarchy-type($FACET : facet, $ASSOC : facet-hierarchy-type)," + ! " direct-instance-of($SUPER, superordinate-role)," + ! " direct-instance-of($SUB, subordinate-role)," + ! " { $ASSOC($SUBFV : $SUB, $SUPERFV : $SUPER) " + ! " |" + ! " $ASSOC($SUBFV : $SUB, $X : $SUPER)," + ! " subfacet-of($X, $SUPERFV, $FACET)" + ! " }.", ! ! "direct-subfacet-of($SUBFV, $SUPERFV, $FACET) :- " + ! " facet-has-hierarchy-type($FACET:facet, $ASSOC:facet-hierarchy-type)," + ! " direct-instance-of($SUPER, superordinate-role)," + ! " direct-instance-of($SUB, subordinate-role)," + ! " $ASSOC($SUBFV:$SUB, $SUPERFV:$SUPER).", ! ! }; ! ! public void testRecursiveRules() throws Exception { ! doQuery( ! getTopicMap("tolog.facets"), ! auto_rules, ! "select $AUTO from matches-facet(body-type, hatchback, $AUTO) ?", ! new String[][] { ! new String [] {"clio1_2"}, ! new String [] {"astra1_2"}, ! new String [] {"peugot206"}, ! new String [] {"peugot307"}, ! }); ! } ! ! public void testRecursiveRulesList() throws Exception { ! doQuery( ! getTopicMap("tolog.facets"), ! auto_rules, ! "select $INST from matches-facet(body-type,hatchback,$INST), matches-facet(engine-type,petrol,$INST) ?", ! new String[][] { ! new String [] {"clio1_2"}, ! new String [] {"astra1_2"}, ! new String [] {"peugot206"}, ! }); ! } ! ! public void testRecursiveRulesList2() throws Exception { ! TopicMap tm = getTopicMap("tolog.facets"); ! QueryEvaluator qe = QueryEvaluatorFactory.newQueryEvaluator(tm); ! for (int i = 0; i < auto_rules.length; i++) { ! qe.addRule(auto_rules[i]); ! } ! TologResultsSet rs = null; ! rs = qe.execute("select $SUB from direct-subfacet-of($SUB, all-body-types, body-type) ?"); ! assertEquals(5, rs.getNumRows()); ! rs = qe.execute("select $S from subfacet-of($S, all-body-types, body-type) ?"); ! assertEquals(8, rs.getNumRows()); ! rs = qe.execute("select $AUTO from matches-facet(body-type, all-body-types, $AUTO) ?"); ! assertEquals(7, rs.getNumRows()); ! rs = qe.execute("select $AUTO from matches-facet(engine-type, all-engine-types, $AUTO) ?"); ! assertEquals(7, rs.getNumRows()); ! rs = qe.execute("select $AUTO from matches-facet(engine-size, all-engine-sizes, $AUTO) ?"); ! assertEquals(7, rs.getNumRows()); ! rs = qe.execute("select $AUTO from matches-facet(body-type, all-body-types, $AUTO), matches-facet(engine-type, all-engine-types, $AUTO), matches-facet(engine-size, all-engine-sizes, $AUTO) ?"); ! assertEquals(7, rs.getNumRows()); ! this.validateResultsSet(rs, ! new String[][] { ! new String [] {"clio1_2"}, ! new String [] {"astra1_2"}, ! new String [] {"peugot206"}, ! new String [] {"peugot307"}, ! new String [] {"almera1_8"}, ! new String [] {"zafira2_0"}, ! new String [] {"frontera2_2"}}); ! } ! ! public void testRuleWithNoMatch() throws Exception { ! TopicMap tm = getTopicMap("tolog.facets"); ! QueryEvaluator qe = QueryEvaluatorFactory.newQueryEvaluator(tm); ! qe.addRule( ! "direct-subfacet-of($SUBFV, $SUPERFV, $FACET) :- " + ! "facet-has-hierarchy-type($FACET:facet, $ASSOC:facet-hierarchy-type)," + ! "$ASSOC($SUBFV:$SUB, $SUPERFV:$SUPER)," + ! "direct-instance-of($SUPER, superordinate-role)," + ! "direct-instance-of($SUB, subordinate-role)."); ! qe.addRule( ! "subfacet-of($SUBFV, $SUPERFV, $FACET) :- " + ! "{ direct-subfacet-of($SUBFV, $X, $FACET), subfacet-of($X, $SUPERFV, $FACET) " + ! " | direct-subfacet-of($SUBFV, $SUPERFV, $FACET) }."); ! qe.addRule( ! "matches-facet($FACET, $FV, $INST) :- " + ! "{ subfacet-of($C,$FV,$FACET), classified-as($INST:instance, $C:classification)" + ! " | classified-as($INST:instance, $FV:classification) }."); ! TologResultsSet rs = null; ! rs = qe.execute("select $CHILD from direct-subfacet-of($CHILD, @petrol, @engine-type) ?"); ! dumpResultsSet(rs); ! assertEquals(0, rs.getNumRows()); ! } ! ! public void testReifiesPredicate() throws Exception { ! TopicMap tm = getTopicMap("tolog.reification"); ! /* ! doQuery( ! tm, ! "select $REIFIER from reifies($REIFIER, a1) ?", ! new String[][] { ! new String [] {"re-a1"}, ! }); ! */ ! doQuery( ! tm, ! "select $REIFIED from reifies(re-a1, $REIFIED) ?", ! new String[][] { ! new String [] {"a1"}, ! }); ! doQuery( ! tm, "select $REIFIER, $REIFIED from reifies($REIFIER, $REIFIED) ?", ! new String [][] { ! new String [] {"re-a1", "a1"} ! }); ! } ! } ! |
Update of /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30131/src/org/tmapiutils/query/tolog/predicates/test Modified Files: AssociationPredicateTest.java AssociationRolePredicateTest.java BaseLocatorPredicateTest.java DirectInstanceOfPredicateTest.java DynamicAssociationPredicateTest.java InstanceOfPredicateTest.java OccurrencePredicateTest.java PredicateTestBase.java ReifiesPredicateTest.java ResourcePredicateTest.java TopicMapPredicateTest.java TopicNameTest.java TypePredicateTest.java ValueLikePredicateTest.java ValuePredicateTest.java VariantPredicateTest.java Log Message: Tabs -> Whitespaces Index: ResourcePredicateTest.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test/ResourcePredicateTest.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ResourcePredicateTest.java 9 Mar 2005 12:40:19 -0000 1.6 --- ResourcePredicateTest.java 8 Jul 2005 16:03:21 -0000 1.7 *************** *** 1,165 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.predicates.test; ! ! import java.util.ArrayList; ! import java.util.Iterator; ! import java.util.List; ! ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.predicates.ResourcePredicate; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! // TMAPI ! import org.tmapi.core.Locator; ! import org.tmapi.core.TopicMap; ! import org.tmapi.core.Topic; ! import org.tmapi.core.Occurrence; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class ResourcePredicateTest extends PredicateTestBase { ! ! /** ! * @param name ! */ ! public ResourcePredicateTest(String name) { ! super(name); ! } ! ! private static final String TESTMAP = ! "[techquila]\n" + ! "{techquila, homepage, \"http://www.techquila.com/\"}\n" + ! "{techquila, contact-details, \"http://www.techquila.com/contact.html\"}" + ! "[tm4j]\n" + ! "{tm4j, homepage, \"http://www.tm4j.org/\"}"; ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.test.PredicateTestBase#getTestMap() ! */ ! public String getTestMap() { ! return TESTMAP; ! } ! ! ! public void createTestMap(TopicMap tm) { ! Topic tmapiutils = tm.createTopic(); ! Topic homepage = tm.createTopic(); ! Topic contact_details = tm.createTopic(); ! tmapiutils.createOccurrence(createLocator("http://tmapiutils.org/"), homepage, null); ! tmapiutils.createOccurrence(createLocator("http://tmapiutils.org/contact/"), contact_details, null); ! Topic tmapi = tm.createTopic(); ! tmapi.createOccurrence(createLocator("http://tmapi.org/"), homepage, null); ! ! registerObject("tmapiutils", tmapiutils); ! registerObject("homepage", homepage); ! registerObject("tmapi", tmapi); ! } ! ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.test.PredicateTestBase#getPredicateClass() ! */ ! public Class getPredicateClass() { ! return ResourcePredicate.class; ! } ! ! public static void main(String[] args) { ! junit.textui.TestRunner.run(OccurrencePredicateTest.class); ! } ! ! public void testOpenMatch() throws Exception { ! List params = new ArrayList(); ! Variable a = new Variable("A"); ! Variable b = new Variable("B"); ! params.add(a); ! params.add(b); ! m_predicate.setParameters(params); ! VariableSet out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(2, out.getColumns().size()); ! assertEquals(3, out.getRows().size()); ! Iterator it = ((Topic) getObjectById("tmapiutils")).getOccurrences().iterator(); ! while (it.hasNext()) { ! Occurrence o = (Occurrence)it.next(); ! int ix = out.getColumn(a).indexOf(o); ! assertTrue("Expected occurrence to be in results set.", ix > -1); ! Locator l = (Locator)out.getColumn(b).get(ix); ! assertTrue(l.equals(o.getResource())); ! } ! it = ((Topic) getObjectById("tmapiutils")).getOccurrences().iterator(); ! while (it.hasNext()) { ! Occurrence o = (Occurrence)it.next(); ! int ix = out.getColumn(a).indexOf(o); ! assertTrue("Expected occurrence to be in results set.", ix > -1); ! Locator l = (Locator)out.getColumn(b).get(ix); ! assertTrue(l.equals(o.getResource())); ! } ! } ! ! public void testOccurrenceByLocator() throws Exception { ! List params = new ArrayList(); ! Variable a = new Variable("A"); ! Locator loc = m_tm.createLocator("http://tmapiutils.org/"); ! params.add(a); ! params.add(loc); ! m_predicate.setParameters(params); ! VariableSet out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(1, out.getColumns().size()); ! assertEquals(1, out.getRows().size()); ! Iterator it = ((Topic) getObjectById("tmapiutils")).getOccurrences().iterator(); ! while (it.hasNext()) { ! Occurrence o = (Occurrence)it.next(); ! if (o.getResource().equals(loc)) { ! assertTrue(out.getColumn(a).contains(o)); ! } else { ! assertFalse(out.getColumn(a).contains(o)); ! } ! } ! } ! ! public void testLocatorByOccurrence() throws Exception { ! List params = new ArrayList(); ! Variable b = new Variable("B"); ! Locator loc = m_tm.createLocator("http://tmapiutils.org/"); ! Occurrence o = null; ! Iterator it = ((Topic) getObjectById("tmapiutils")).getOccurrences().iterator(); ! while (it.hasNext()) { ! o = (Occurrence)it.next(); ! if (o.getResource().equals(loc)) { ! break; ! } ! } ! assertNotNull("INTERNAL ERROR: Did not find occurrence to use in the query test.", o); ! params.add(o); ! params.add(b); ! m_predicate.setParameters(params); ! VariableSet out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(1, out.getColumns().size()); ! assertEquals(1, out.getRows().size()); ! assertTrue(out.getColumn(b).contains(loc)); ! } ! ! // TODO: Implement tests for closed matches. ! // Variant Tests! ! } ! --- 1,165 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.predicates.test; ! ! import java.util.ArrayList; ! import java.util.Iterator; ! import java.util.List; ! ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.predicates.ResourcePredicate; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! // TMAPI ! import org.tmapi.core.Locator; ! import org.tmapi.core.TopicMap; ! import org.tmapi.core.Topic; ! import org.tmapi.core.Occurrence; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class ResourcePredicateTest extends PredicateTestBase { ! ! /** ! * @param name ! */ ! public ResourcePredicateTest(String name) { ! super(name); ! } ! ! private static final String TESTMAP = ! "[techquila]\n" + ! "{techquila, homepage, \"http://www.techquila.com/\"}\n" + ! "{techquila, contact-details, \"http://www.techquila.com/contact.html\"}" + ! "[tm4j]\n" + ! "{tm4j, homepage, \"http://www.tm4j.org/\"}"; ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.test.PredicateTestBase#getTestMap() ! */ ! public String getTestMap() { ! return TESTMAP; ! } ! ! ! public void createTestMap(TopicMap tm) { ! Topic tmapiutils = tm.createTopic(); ! Topic homepage = tm.createTopic(); ! Topic contact_details = tm.createTopic(); ! tmapiutils.createOccurrence(createLocator("http://tmapiutils.org/"), homepage, null); ! tmapiutils.createOccurrence(createLocator("http://tmapiutils.org/contact/"), contact_details, null); ! Topic tmapi = tm.createTopic(); ! tmapi.createOccurrence(createLocator("http://tmapi.org/"), homepage, null); ! ! registerObject("tmapiutils", tmapiutils); ! registerObject("homepage", homepage); ! registerObject("tmapi", tmapi); ! } ! ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.test.PredicateTestBase#getPredicateClass() ! */ ! public Class getPredicateClass() { ! return ResourcePredicate.class; ! } ! ! public static void main(String[] args) { ! junit.textui.TestRunner.run(OccurrencePredicateTest.class); ! } ! ! public void testOpenMatch() throws Exception { ! List params = new ArrayList(); ! Variable a = new Variable("A"); ! Variable b = new Variable("B"); ! params.add(a); ! params.add(b); ! m_predicate.setParameters(params); ! VariableSet out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(2, out.getColumns().size()); ! assertEquals(3, out.getRows().size()); ! Iterator it = ((Topic) getObjectById("tmapiutils")).getOccurrences().iterator(); ! while (it.hasNext()) { ! Occurrence o = (Occurrence)it.next(); ! int ix = out.getColumn(a).indexOf(o); ! assertTrue("Expected occurrence to be in results set.", ix > -1); ! Locator l = (Locator)out.getColumn(b).get(ix); ! assertTrue(l.equals(o.getResource())); ! } ! it = ((Topic) getObjectById("tmapiutils")).getOccurrences().iterator(); ! while (it.hasNext()) { ! Occurrence o = (Occurrence)it.next(); ! int ix = out.getColumn(a).indexOf(o); ! assertTrue("Expected occurrence to be in results set.", ix > -1); ! Locator l = (Locator)out.getColumn(b).get(ix); ! assertTrue(l.equals(o.getResource())); ! } ! } ! ! public void testOccurrenceByLocator() throws Exception { ! List params = new ArrayList(); ! Variable a = new Variable("A"); ! Locator loc = m_tm.createLocator("http://tmapiutils.org/"); ! params.add(a); ! params.add(loc); ! m_predicate.setParameters(params); ! VariableSet out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(1, out.getColumns().size()); ! assertEquals(1, out.getRows().size()); ! Iterator it = ((Topic) getObjectById("tmapiutils")).getOccurrences().iterator(); ! while (it.hasNext()) { ! Occurrence o = (Occurrence)it.next(); ! if (o.getResource().equals(loc)) { ! assertTrue(out.getColumn(a).contains(o)); ! } else { ! assertFalse(out.getColumn(a).contains(o)); ! } ! } ! } ! ! public void testLocatorByOccurrence() throws Exception { ! List params = new ArrayList(); ! Variable b = new Variable("B"); ! Locator loc = m_tm.createLocator("http://tmapiutils.org/"); ! Occurrence o = null; ! Iterator it = ((Topic) getObjectById("tmapiutils")).getOccurrences().iterator(); ! while (it.hasNext()) { ! o = (Occurrence)it.next(); ! if (o.getResource().equals(loc)) { ! break; ! } ! } ! assertNotNull("INTERNAL ERROR: Did not find occurrence to use in the query test.", o); ! params.add(o); ! params.add(b); ! m_predicate.setParameters(params); ! VariableSet out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(1, out.getColumns().size()); ! assertEquals(1, out.getRows().size()); ! assertTrue(out.getColumn(b).contains(loc)); ! } ! ! // TODO: Implement tests for closed matches. ! // Variant Tests! ! } ! Index: PredicateTestBase.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test/PredicateTestBase.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** PredicateTestBase.java 9 Mar 2005 12:40:19 -0000 1.8 --- PredicateTestBase.java 8 Jul 2005 16:03:21 -0000 1.9 *************** *** 1,114 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.predicates.test; ! ! import java.util.Iterator; ! import java.util.HashMap; ! ! import junit.framework.TestCase; ! ! import org.tmapiutils.query.tolog.parser.Predicate; ! import org.tmapiutils.query.tolog.utils.TologContext; ! // TMAPI ! import org.tmapi.core.Locator; ! import org.tmapi.core.TopicMapSystemFactory; ! import org.tmapi.core.TopicMapSystem; ! import org.tmapi.core.TopicMapObject; ! import org.tmapi.core.TopicMap; ! import org.tmapi.core.TMAPIException; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public abstract class PredicateTestBase extends TestCase { ! ! ! protected Predicate m_predicate; ! protected TopicMap m_tm; ! private HashMap _maps; ! private HashMap _objectMap; ! protected static TopicMapSystem _tmSystem; ! protected TologContext m_context; ! ! /** ! * Creates a topic map to work with. ! */ ! public abstract void createTestMap(TopicMap tm); ! public abstract Class getPredicateClass(); ! ! public PredicateTestBase(String name) { ! super(name); ! _maps = new HashMap(); ! _objectMap = new HashMap(); ! } ! ! public void setUp() throws Exception { ! super.setUp(); ! _tmSystem = TopicMapSystemFactory.newInstance().newTopicMapSystem(); ! removeAllMaps(); ! m_tm = createTopicMap("http://tmapiutils.org/test/tolog1.0/"); ! createTestMap(m_tm); ! m_predicate = (Predicate) getPredicateClass().newInstance(); ! m_predicate.initialise(m_tm); ! m_context = new TologContext(); ! } ! ! protected void tearDown() throws Exception{ ! super.tearDown(); ! _objectMap.clear(); ! // remove created TopicMaps from TopicMapSystem ! removeAllMaps(); ! // Close TopicMapSystem instance ! _tmSystem.close(); ! } ! ! protected void registerObject(String name, TopicMapObject obj) { ! _objectMap.put(name, obj); ! } ! ! protected TopicMapObject getObjectById(String name) { ! TopicMapObject obj = (TopicMapObject) _objectMap.get(name); ! if (obj == null) { ! throw new RuntimeException("Object Id not found :" + name); ! } ! return obj; ! } ! ! protected Locator createLocator(String reference) { ! return m_tm.createLocator(reference); ! } ! ! protected void removeAllMaps() throws TMAPIException { ! for (Iterator iter = _tmSystem.getBaseLocators().iterator(); iter.hasNext();) { ! removeTopicMap(_tmSystem.getTopicMap((Locator)iter.next())); ! } ! } ! ! protected TopicMap createTopicMap(String reference) throws TMAPIException { ! TopicMap tm = _tmSystem.createTopicMap(reference); ! _maps.put(reference, tm); ! return tm; ! } ! ! protected void removeTopicMap(TopicMap tm) throws TMAPIException { ! _maps.remove(tm.getBaseLocator().getReference()); ! tm.remove(); ! } ! } --- 1,114 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.predicates.test; ! ! import java.util.Iterator; ! import java.util.HashMap; ! ! import junit.framework.TestCase; ! ! import org.tmapiutils.query.tolog.parser.Predicate; ! import org.tmapiutils.query.tolog.utils.TologContext; ! // TMAPI ! import org.tmapi.core.Locator; ! import org.tmapi.core.TopicMapSystemFactory; ! import org.tmapi.core.TopicMapSystem; ! import org.tmapi.core.TopicMapObject; ! import org.tmapi.core.TopicMap; ! import org.tmapi.core.TMAPIException; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public abstract class PredicateTestBase extends TestCase { ! ! ! protected Predicate m_predicate; ! protected TopicMap m_tm; ! private HashMap _maps; ! private HashMap _objectMap; ! protected static TopicMapSystem _tmSystem; ! protected TologContext m_context; ! ! /** ! * Creates a topic map to work with. ! */ ! public abstract void createTestMap(TopicMap tm); ! public abstract Class getPredicateClass(); ! ! public PredicateTestBase(String name) { ! super(name); ! _maps = new HashMap(); ! _objectMap = new HashMap(); ! } ! ! public void setUp() throws Exception { ! super.setUp(); ! _tmSystem = TopicMapSystemFactory.newInstance().newTopicMapSystem(); ! removeAllMaps(); ! m_tm = createTopicMap("http://tmapiutils.org/test/tolog1.0/"); ! createTestMap(m_tm); ! m_predicate = (Predicate) getPredicateClass().newInstance(); ! m_predicate.initialise(m_tm); ! m_context = new TologContext(); ! } ! ! protected void tearDown() throws Exception{ ! super.tearDown(); ! _objectMap.clear(); ! // remove created TopicMaps from TopicMapSystem ! removeAllMaps(); ! // Close TopicMapSystem instance ! _tmSystem.close(); ! } ! ! protected void registerObject(String name, TopicMapObject obj) { ! _objectMap.put(name, obj); ! } ! ! protected TopicMapObject getObjectById(String name) { ! TopicMapObject obj = (TopicMapObject) _objectMap.get(name); ! if (obj == null) { ! throw new RuntimeException("Object Id not found :" + name); ! } ! return obj; ! } ! ! protected Locator createLocator(String reference) { ! return m_tm.createLocator(reference); ! } ! ! protected void removeAllMaps() throws TMAPIException { ! for (Iterator iter = _tmSystem.getBaseLocators().iterator(); iter.hasNext();) { ! removeTopicMap(_tmSystem.getTopicMap((Locator)iter.next())); ! } ! } ! ! protected TopicMap createTopicMap(String reference) throws TMAPIException { ! TopicMap tm = _tmSystem.createTopicMap(reference); ! _maps.put(reference, tm); ! return tm; ! } ! ! protected void removeTopicMap(TopicMap tm) throws TMAPIException { ! _maps.remove(tm.getBaseLocator().getReference()); ! tm.remove(); ! } ! } Index: TopicMapPredicateTest.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test/TopicMapPredicateTest.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** TopicMapPredicateTest.java 9 Mar 2005 12:40:19 -0000 1.5 --- TopicMapPredicateTest.java 8 Jul 2005 16:03:21 -0000 1.6 *************** *** 1,90 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.predicates.test; ! ! import java.util.ArrayList; ! ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.predicates.TopicMapPredicate; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! // TMAPI ! import org.tmapi.core.TopicMapObject; ! import org.tmapi.core.TopicMap; ! import org.tmapi.core.Topic; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class TopicMapPredicateTest extends PredicateTestBase { ! ! /** ! * @param name ! */ ! public TopicMapPredicateTest(String name) { ! super(name); ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.test.PredicateTestBase#getTestMap() ! */ ! public String getTestMap() { ! return "[hello-world]"; ! } ! ! public void createTestMap(TopicMap tm) { ! Topic topic = tm.createTopic(); ! ! registerObject("hello-world", topic); ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.test.PredicateTestBase#getPredicateClass() ! */ ! public Class getPredicateClass() { ! return TopicMapPredicate.class; ! } ! ! public void testOpenMatch() throws Exception { ! ArrayList params = new ArrayList(); ! params.add(new Variable("A")); ! m_predicate.setParameters(params); ! VariableSet out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(1, out.getRows().size()); ! assertEquals(m_tm, out.getRow(0).get(0)); ! } ! ! public void testClosedMatch() throws Exception { ! ArrayList params = new ArrayList(); ! params.add(new Variable("A")); ! m_predicate.setParameters(params); ! params.set(0, m_tm); ! VariableSet out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(1, out.getRows().size()); ! assertEquals(m_tm, out.getRow(0).get(0)); ! ! params.set(0, getObjectById("hello-world")); ! out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(0, out.getRows().size()); ! } ! } ! --- 1,90 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.predicates.test; ! ! import java.util.ArrayList; ! ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.predicates.TopicMapPredicate; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! // TMAPI ! import org.tmapi.core.TopicMapObject; ! import org.tmapi.core.TopicMap; ! import org.tmapi.core.Topic; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class TopicMapPredicateTest extends PredicateTestBase { ! ! /** ! * @param name ! */ ! public TopicMapPredicateTest(String name) { ! super(name); ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.test.PredicateTestBase#getTestMap() ! */ ! public String getTestMap() { ! return "[hello-world]"; ! } ! ! public void createTestMap(TopicMap tm) { ! Topic topic = tm.createTopic(); ! ! registerObject("hello-world", topic); ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.test.PredicateTestBase#getPredicateClass() ! */ ! public Class getPredicateClass() { ! return TopicMapPredicate.class; ! } ! ! public void testOpenMatch() throws Exception { ! ArrayList params = new ArrayList(); ! params.add(new Variable("A")); ! m_predicate.setParameters(params); ! VariableSet out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(1, out.getRows().size()); ! assertEquals(m_tm, out.getRow(0).get(0)); ! } ! ! public void testClosedMatch() throws Exception { ! ArrayList params = new ArrayList(); ! params.add(new Variable("A")); ! m_predicate.setParameters(params); ! params.set(0, m_tm); ! VariableSet out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(1, out.getRows().size()); ! assertEquals(m_tm, out.getRow(0).get(0)); ! ! params.set(0, getObjectById("hello-world")); ! out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(0, out.getRows().size()); ! } ! } ! Index: ReifiesPredicateTest.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test/ReifiesPredicateTest.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ReifiesPredicateTest.java 9 Mar 2005 12:40:19 -0000 1.5 --- ReifiesPredicateTest.java 8 Jul 2005 16:03:21 -0000 1.6 *************** *** 1,164 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.predicates.test; ! ! import java.util.ArrayList; ! ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.predicates.ReifiesPredicate; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! // TMAPI ! import org.tmapi.core.TopicMap; ! import org.tmapi.core.Topic; ! import org.tmapi.core.Association; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class ReifiesPredicateTest extends PredicateTestBase { ! ! /** ! * @param name ! */ ! public ReifiesPredicateTest(String name) { ! super(name); ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.test.PredicateTestBase#getTestMap() ! */ ! public String getTestMap() { ! return "<topicMap xmlns=\"http://www.topicmaps.org/xtm/1.0/\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">" + ! "<topic id=\"fred\"/> <topic id=\"bigco\"/> <topic id=\"worksfor\"/>" + ! "<association id=\"assoc1\">" + ! "<instanceOf><topicRef xlink:href=\"#worksfor\"/></instanceOf>" + ! "<member id=\"m1\"><topicRef xlink:href=\"#fred\"/></member>" + ! "<member id=\"m2\"><topicRef xlink:href=\"#bigco\"/></member>" + ! "</association>" + ! "<topic id=\"fredemp\"> <subjectIdentity><resourceRef xlink:href=\"#assoc1\"/> </subjectIdentity> </topic>" + ! "</topicMap>"; ! } ! ! // public TopicMapBuilder getBuilder() { ! // return new XTMBuilder(); ! // } ! ! public void createTestMap(TopicMap tm) { ! Topic works_for = tm.createTopic(); ! Topic fred = tm.createTopic(); ! Topic barney = tm.createTopic(); ! Topic employee = tm.createTopic(); ! Topic employer = tm.createTopic(); ! Topic bigco = tm.createTopic(); ! Topic fredemp = tm.createTopic(); ! fredemp.addSubjectIdentifier(tm.createLocator("assoc1")); ! ! ! Association assoc1 = tm.createAssociation(); ! assoc1.setType(works_for); ! assoc1.createAssociationRole(fred, employee); ! assoc1.createAssociationRole(bigco, employer); ! assoc1.addSourceLocator(tm.createLocator("assoc1")); ! ! Association assoc2 = tm.createAssociation(); ! assoc2.setType(works_for); ! assoc2.createAssociationRole(barney, employee); ! assoc2.createAssociationRole(bigco, employer); ! ! registerObject("works-for", works_for); ! registerObject("fred", fred); ! registerObject("barney", barney); ! registerObject("employee", employee); ! registerObject("bigco", bigco); ! registerObject("employer", employer); ! registerObject("fredemp", fredemp); ! } ! ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.test.PredicateTestBase#getPredicateClass() ! */ ! public Class getPredicateClass() { ! return ReifiesPredicate.class; ! } ! ! public void testMatchReifier() throws Exception { ! ArrayList params = new ArrayList(); ! Variable a = new Variable("A"); ! params.add(a); ! params.add(getObjectById("assoc1")); ! m_predicate.setParameters(params); ! VariableSet out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(1, out.getColumns().size()); ! assertEquals(1, out.getRows().size()); ! assertTrue(out.getRow(0).contains(getObjectById("fredemp"))); ! } ! ! public void testMatchReified() throws Exception { ! ArrayList params = new ArrayList(); ! Variable a = new Variable("A"); ! params.add(getObjectById("fredemp")); ! params.add(a); ! m_predicate.setParameters(params); ! VariableSet out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(1, out.getColumns().size()); ! assertEquals(1, out.getRows().size()); ! assertTrue(out.getRow(0).contains(getObjectById("fredemp"))); ! } ! ! public void testOpenMatch() throws Exception { ! ArrayList params = new ArrayList(); ! Variable a = new Variable("A"); ! Variable b = new Variable("B"); ! params.add(a); ! params.add(b); ! m_predicate.setParameters(params); ! VariableSet out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(2, out.getColumns().size()); ! assertEquals(1, out.getRows().size()); ! assertTrue(out.getRow(0).get(0).equals(getObjectById("fredemp"))); ! assertTrue(out.getRow(0).get(1).equals(getObjectById("assoc1"))); ! } ! ! public void testClosedMatch() throws Exception { ! ArrayList params = new ArrayList(); ! Variable a = new Variable("A"); ! Variable b = new Variable("B"); ! params.add(a); ! params.add(b); ! m_predicate.setParameters(params); ! params.set(0, getObjectById("fredemp")); ! params.set(1, getObjectById("assoc1")); ! VariableSet out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(2, out.getColumns().size()); ! assertEquals(1, out.getRows().size()); ! params.set(0, getObjectById("fredemp")); ! params.set(1, getObjectById("m1")); ! out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(2, out.getColumns().size()); ! assertEquals(0, out.getRows().size()); ! ! } ! } --- 1,164 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.predicates.test; ! ! import java.util.ArrayList; ! ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.predicates.ReifiesPredicate; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! // TMAPI ! import org.tmapi.core.TopicMap; ! import org.tmapi.core.Topic; ! import org.tmapi.core.Association; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class ReifiesPredicateTest extends PredicateTestBase { ! ! /** ! * @param name ! */ ! public ReifiesPredicateTest(String name) { ! super(name); ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.test.PredicateTestBase#getTestMap() ! */ ! public String getTestMap() { ! return "<topicMap xmlns=\"http://www.topicmaps.org/xtm/1.0/\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">" + ! "<topic id=\"fred\"/> <topic id=\"bigco\"/> <topic id=\"worksfor\"/>" + ! "<association id=\"assoc1\">" + ! "<instanceOf><topicRef xlink:href=\"#worksfor\"/></instanceOf>" + ! "<member id=\"m1\"><topicRef xlink:href=\"#fred\"/></member>" + ! "<member id=\"m2\"><topicRef xlink:href=\"#bigco\"/></member>" + ! "</association>" + ! "<topic id=\"fredemp\"> <subjectIdentity><resourceRef xlink:href=\"#assoc1\"/> </subjectIdentity> </topic>" + ! "</topicMap>"; ! } ! ! // public TopicMapBuilder getBuilder() { ! // return new XTMBuilder(); ! // } ! ! public void createTestMap(TopicMap tm) { ! Topic works_for = tm.createTopic(); ! Topic fred = tm.createTopic(); ! Topic barney = tm.createTopic(); ! Topic employee = tm.createTopic(); ! Topic employer = tm.createTopic(); ! Topic bigco = tm.createTopic(); ! Topic fredemp = tm.createTopic(); ! fredemp.addSubjectIdentifier(tm.createLocator("assoc1")); ! ! ! Association assoc1 = tm.createAssociation(); ! assoc1.setType(works_for); ! assoc1.createAssociationRole(fred, employee); ! assoc1.createAssociationRole(bigco, employer); ! assoc1.addSourceLocator(tm.createLocator("assoc1")); ! ! Association assoc2 = tm.createAssociation(); ! assoc2.setType(works_for); ! assoc2.createAssociationRole(barney, employee); ! assoc2.createAssociationRole(bigco, employer); ! ! registerObject("works-for", works_for); ! registerObject("fred", fred); ! registerObject("barney", barney); ! registerObject("employee", employee); ! registerObject("bigco", bigco); ! registerObject("employer", employer); ! registerObject("fredemp", fredemp); ! } ! ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.test.PredicateTestBase#getPredicateClass() ! */ ! public Class getPredicateClass() { ! return ReifiesPredicate.class; ! } ! ! public void testMatchReifier() throws Exception { ! ArrayList params = new ArrayList(); ! Variable a = new Variable("A"); ! params.add(a); ! params.add(getObjectById("assoc1")); ! m_predicate.setParameters(params); ! VariableSet out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(1, out.getColumns().size()); ! assertEquals(1, out.getRows().size()); ! assertTrue(out.getRow(0).contains(getObjectById("fredemp"))); ! } ! ! public void testMatchReified() throws Exception { ! ArrayList params = new ArrayList(); ! Variable a = new Variable("A"); ! params.add(getObjectById("fredemp")); ! params.add(a); ! m_predicate.setParameters(params); ! VariableSet out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(1, out.getColumns().size()); ! assertEquals(1, out.getRows().size()); ! assertTrue(out.getRow(0).contains(getObjectById("fredemp"))); ! } ! ! public void testOpenMatch() throws Exception { ! ArrayList params = new ArrayList(); ! Variable a = new Variable("A"); ! Variable b = new Variable("B"); ! params.add(a); ! params.add(b); ! m_predicate.setParameters(params); ! VariableSet out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(2, out.getColumns().size()); ! assertEquals(1, out.getRows().size()); ! assertTrue(out.getRow(0).get(0).equals(getObjectById("fredemp"))); ! assertTrue(out.getRow(0).get(1).equals(getObjectById("assoc1"))); ! } ! ! public void testClosedMatch() throws Exception { ! ArrayList params = new ArrayList(); ! Variable a = new Variable("A"); ! Variable b = new Variable("B"); ! params.add(a); ! params.add(b); ! m_predicate.setParameters(params); ! params.set(0, getObjectById("fredemp")); ! params.set(1, getObjectById("assoc1")); ! VariableSet out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(2, out.getColumns().size()); ! assertEquals(1, out.getRows().size()); ! params.set(0, getObjectById("fredemp")); ! params.set(1, getObjectById("m1")); ! out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(2, out.getColumns().size()); ! assertEquals(0, out.getRows().size()); ! ! } ! } Index: AssociationRolePredicateTest.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test/AssociationRolePredicateTest.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** AssociationRolePredicateTest.java 9 Mar 2005 12:40:19 -0000 1.5 --- AssociationRolePredicateTest.java 8 Jul 2005 16:03:21 -0000 1.6 *************** *** 1,165 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.predicates.test; ! ! import java.util.ArrayList; ! import java.util.Iterator; ! import java.util.List; ! ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.predicates.AssociationRolePredicate; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! // TMAPI ! import org.tmapi.core.Topic; ! import org.tmapi.core.TopicMap; ! import org.tmapi.core.Association; ! import org.tmapi.core.AssociationRole; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class AssociationRolePredicateTest extends PredicateTestBase { ! ! ! /** ! * @param name ! */ ! public AssociationRolePredicateTest(String name) { ! super(name); ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.test.PredicateTestBase#getTestMap() ! */ ! public String getTestMap() { ! return "works-for(fred:employee, bigco:employer)\n" + ! "works-for(barney:employee, bigco:employer)\n"; ! } ! ! ! public void createTestMap(TopicMap tm) { ! Topic works_for = tm.createTopic(); ! Topic fred = tm.createTopic(); ! Topic barney = tm.createTopic(); ! Topic employee = tm.createTopic(); ! Topic employer = tm.createTopic(); ! Topic bigco = tm.createTopic(); ! ! Association assoc1 = tm.createAssociation(); ! assoc1.setType(works_for); ! assoc1.createAssociationRole(fred, employee); ! assoc1.createAssociationRole(bigco, employer); ! ! Association assoc2 = tm.createAssociation(); ! assoc2.setType(works_for); ! assoc2.createAssociationRole(barney, employee); ! assoc2.createAssociationRole(bigco, employer); ! ! registerObject("works-for", works_for); ! registerObject("fred", fred); ! registerObject("barney", barney); ! registerObject("employee", employee); ! registerObject("bigco", bigco); ! registerObject("employer", employer); ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.test.PredicateTestBase#getPredicateClass() ! */ ! public Class getPredicateClass() { ! return AssociationRolePredicate.class; ! } ! ! public void testMatchAssociation() throws Exception { ! ArrayList params = new ArrayList(); ! Variable a = new Variable("A"); ! Topic fred = (Topic) getObjectById("fred"); ! AssociationRole role = (AssociationRole) fred.getRolesPlayed().iterator().next(); ! params.add(a); ! params.add(role); ! m_predicate.setParameters(params); ! VariableSet out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(1, out.getColumns().size()); ! assertEquals(1, out.getRows().size()); ! assertEquals(role.getAssociation(), out.getRow(0).get(0)); ! } ! ! public void testMatchRoles() throws Exception { ! ArrayList params = new ArrayList(); ! Topic barney =(Topic) getObjectById("barney"); ! Association assoc = ((AssociationRole) barney.getRolesPlayed().iterator().next()).getAssociation(); ! Variable a = new Variable("A"); ! params.add(assoc); ! params.add(a); ! m_predicate.setParameters(params); ! VariableSet out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(1, out.getColumns().size()); ! assertEquals(2, out.getRows().size()); ! assertEquals(assoc, ((AssociationRole)out.getRow(0).get(0)).getAssociation()); ! assertEquals(assoc, ((AssociationRole)out.getRow(1).get(0)).getAssociation()); ! } ! ! public void testOpenMatch() throws Exception { ! ArrayList params = new ArrayList(); ! Variable a = new Variable("A"); ! Variable b = new Variable("B"); ! params.add(a); ! params.add(b); ! m_predicate.setParameters(params); ! VariableSet out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(2, out.getColumns().size()); ! assertEquals(4, out.getRows().size()); ! Iterator it = out.getRows().iterator(); ! while (it.hasNext()) { ! List row = (List)it.next(); ! assertEquals(row.get(0), ((AssociationRole)row.get(1)).getAssociation()); ! } ! } ! ! public void testClosedMatch() throws Exception { ! ArrayList params = new ArrayList(); ! Variable a = new Variable("A"); ! Variable b = new Variable("B"); ! params.add(a); ! params.add(b); ! m_predicate.setParameters(params); ! Topic fred = (Topic) getObjectById("fred"); ! AssociationRole role = (AssociationRole) fred.getRolesPlayed().iterator().next(); ! Association assoc = role.getAssociation(); ! params.set(0, assoc); ! params.set(1, role); ! VariableSet out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(2, out.getColumns().size()); ! assertEquals(1, out.getRows().size()); ! ! Topic barney =(Topic) getObjectById("barney"); ! AssociationRole role2 = (AssociationRole)barney.getRolesPlayed().iterator().next(); ! params.set(1, role2); ! out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(2, out.getColumns().size()); ! assertEquals(0, out.getRows().size()); ! } ! } ! --- 1,165 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.predicates.test; ! ! import java.util.ArrayList; ! import java.util.Iterator; ! import java.util.List; ! ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.predicates.AssociationRolePredicate; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! // TMAPI ! import org.tmapi.core.Topic; ! import org.tmapi.core.TopicMap; ! import org.tmapi.core.Association; ! import org.tmapi.core.AssociationRole; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class AssociationRolePredicateTest extends PredicateTestBase { ! ! ! /** ! * @param name ! */ ! public AssociationRolePredicateTest(String name) { ! super(name); ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.test.PredicateTestBase#getTestMap() ! */ ! public String getTestMap() { ! return "works-for(fred:employee, bigco:employer)\n" + ! "works-for(barney:employee, bigco:employer)\n"; ! } ! ! ! public void createTestMap(TopicMap tm) { ! Topic works_for = tm.createTopic(); ! Topic fred = tm.createTopic(); ! Topic barney = tm.createTopic(); ! Topic employee = tm.createTopic(); ! Topic employer = tm.createTopic(); ! Topic bigco = tm.createTopic(); ! ! Association assoc1 = tm.createAssociation(); ! assoc1.setType(works_for); ! assoc1.createAssociationRole(fred, employee); ! assoc1.createAssociationRole(bigco, employer); ! ! Association assoc2 = tm.createAssociation(); ! assoc2.setType(works_for); ! assoc2.createAssociationRole(barney, employee); ! assoc2.createAssociationRole(bigco, employer); ! ! registerObject("works-for", works_for); ! registerObject("fred", fred); ! registerObject("barney", barney); ! registerObject("employee", employee); ! registerObject("bigco", bigco); ! registerObject("employer", employer); ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.test.PredicateTestBase#getPredicateClass() ! */ ! public Class getPredicateClass() { ! return AssociationRolePredicate.class; ! } ! ! public void testMatchAssociation() throws Exception { ! ArrayList params = new ArrayList(); ! Variable a = new Variable("A"); ! Topic fred = (Topic) getObjectById("fred"); ! AssociationRole role = (AssociationRole) fred.getRolesPlayed().iterator().next(); ! params.add(a); ! params.add(role); ! m_predicate.setParameters(params); ! VariableSet out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(1, out.getColumns().size()); ! assertEquals(1, out.getRows().size()); ! assertEquals(role.getAssociation(), out.getRow(0).get(0)); ! } ! ! public void testMatchRoles() throws Exception { ! ArrayList params = new ArrayList(); ! Topic barney =(Topic) getObjectById("barney"); ! Association assoc = ((AssociationRole) barney.getRolesPlayed().iterator().next()).getAssociation(); ! Variable a = new Variable("A"); ! params.add(assoc); ! params.add(a); ! m_predicate.setParameters(params); ! VariableSet out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(1, out.getColumns().size()); ! assertEquals(2, out.getRows().size()); ! assertEquals(assoc, ((AssociationRole)out.getRow(0).get(0)).getAssociation()); ! assertEquals(assoc, ((AssociationRole)out.getRow(1).get(0)).getAssociation()); ! } ! ! public void testOpenMatch() throws Exception { ! ArrayList params = new ArrayList(); ! Variable a = new Variable("A"); ! Variable b = new Variable("B"); ! params.add(a); ! params.add(b); ! m_predicate.setParameters(params); ! VariableSet out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(2, out.getColumns().size()); ! assertEquals(4, out.getRows().size()); ! Iterator it = out.getRows().iterator(); ! while (it.hasNext()) { ! List row = (List)it.next(); ! assertEquals(row.get(0), ((AssociationRole)row.get(1)).getAssociation()); ! } ! } ! ! public void testClosedMatch() throws Exception { ! ArrayList params = new ArrayList(); ! Variable a = new Variable("A"); ! Variable b = new Variable("B"); ! params.add(a); ! params.add(b); ! m_predicate.setParameters(params); ! Topic fred = (Topic) getObjectById("fred"); ! AssociationRole role = (AssociationRole) fred.getRolesPlayed().iterator().next(); ! Association assoc = role.getAssociation(); ! params.set(0, assoc); ! params.set(1, role); ! VariableSet out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(2, out.getColumns().size()); ! assertEquals(1, out.getRows().size()); ! ! Topic barney =(Topic) getObjectById("barney"); ! AssociationRole role2 = (AssociationRole)barney.getRolesPlayed().iterator().next(); ! params.set(1, role2); ! out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(2, out.getColumns().size()); ! assertEquals(0, out.getRows().size()); ! } ! } ! Index: DirectInstanceOfPredicateTest.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test/DirectInstanceOfPredicateTest.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** DirectInstanceOfPredicateTest.java 9 Mar 2005 12:40:19 -0000 1.7 --- DirectInstanceOfPredicateTest.java 8 Jul 2005 16:03:21 -0000 1.8 *************** *** 1,157 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.predicates.test; ! ! import java.util.ArrayList; ! import java.util.List; ! ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.predicates.DirectInstanceOfPredicate; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! // TMAPI ! import org.tmapi.core.TopicMap; ! import org.tmapi.core.Topic; ! ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class DirectInstanceOfPredicateTest extends PredicateTestBase { ! ! ! /** ! * Constructor for DirectInstanceOfPredicateTest. ! * @param arg0 ! */ ! public DirectInstanceOfPredicateTest(String arg0) { ! super(arg0); ! } ! ! public Class getPredicateClass() { ! return DirectInstanceOfPredicate.class; ! } ! ! private static final String TESTMAP = ! "[digestive:biscuit]\n" + ! "[battenburg:cake]\n" + ! "[jaffacake:cake]\n" + ! "[jaffacake:biscuit]\n" + ! "[custardcream:biscuit]\n"; ! ! ! public void createTestMap(TopicMap tm) { ! Topic digestive = tm.createTopic(); ! Topic biscuit = tm.createTopic(); ! Topic battenburg = tm.createTopic(); ! Topic cake = tm.createTopic(); ! Topic jaffacake = tm.createTopic(); ! Topic custardcream = tm.createTopic(); ! ! digestive.addType(biscuit); ! battenburg.addType(cake); ! jaffacake.addType(cake); ! jaffacake.addType(biscuit); ! custardcream.addType(biscuit); ! ! registerObject("digestive", digestive); ! registerObject("biscuit", biscuit); ! registerObject("battenburg", battenburg); ! registerObject("cake", cake); ! registerObject("jaffacake", jaffacake); ! registerObject("custardcream", custardcream); ! } ! ! ! public void testOpenMatch() throws Exception ! { ! List params = new ArrayList(); ! Variable a = new Variable("A"); ! Variable b = new Variable("B"); ! params.add(a); ! params.add(b); ! m_predicate.setParameters(params); ! VariableSet out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(2, out.getColumns().size()); ! assertEquals(5, out.getRows().size()); ! assertTrue(out.getColumn(a).contains(getObjectById("digestive"))); ! assertTrue(out.getColumn(a).contains(getObjectById("battenburg"))); ! assertTrue(out.getColumn(a).contains(getObjectById("custardcream"))); ! assertTrue(out.getColumn(a).contains(getObjectById("jaffacake"))); ! assertTrue(out.getColumn(b).contains(getObjectById("biscuit"))); ! assertTrue(out.getColumn(b).contains(getObjectById("cake"))); ! } ! ! public void testClassMatch() throws Exception ! { ! List params = new ArrayList(); ! Variable a = new Variable("A"); ! params.add(a); ! params.add(m_tm.getObjectById("cake")); ! m_predicate.setParameters(params); ! VariableSet out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(1, out.getColumns().size()); ! assertEquals(2, out.getRows().size()); ! assertTrue(out.getColumn(a).contains(getObjectById("battenburg"))); ! assertTrue(out.getColumn(a).contains(getObjectById("jaffacake"))); ! } ! ! public void testInstanceMatch() throws Exception { ! List params = new ArrayList(); ! Variable a = new Variable("A"); ! params.add(getObjectById("jaffacake")); ! params.add(a); ! m_predicate.setParameters(params); ! VariableSet out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(1, out.getColumns().size()); ! assertEquals(2, out.getRows().size()); ! assertTrue(out.getColumn(a).contains(getObjectById("cake"))); ! assertTrue(out.getColumn(a).contains(getObjectById("biscuit"))); ! } ! ! public void testClosedMatch() throws Exception { ! List params = new ArrayList(); ! Variable a = new Variable("A"); ! params.add(a); ! params.add(getObjectById("cake")); ! m_predicate.setParameters(params); ! params.set(0, getObjectById("jaffacake")); ! VariableSet out = m_predicate.matches(params, m_context); ! assertNotNull(out); ! assertEquals(1, out.getColumns().size()); ! assertEquals(1, out.getRows().size()); ! assertTrue(out.getColumn(a).contains(getObjectById("jaffacake"))); ! } ! ! // protected void setUp() throws Exception { ! // TopicMapProviderFactory tmpf = new TopicMapProviderFactoryImpl(); ! // m_provider = tmpf.newTopicMapProvider(); ! // Locator loc = m_provider.getLocatorFactory().createLocator("URI", "http://www.techquila.com/test/tolog1.0.xtm"); ! // SerializedTopicMapSource src = new SerializedTopicMapSource(new StringReader(TESTMAP), loc, new LTMBuilder()); ! // m_tm = m_provider.addTopicMap(src); ! // m_predicate = new DirectInstanceOfPredicate(); ! // m_predicate.initialise(m_tm); ! // m_context = new TologContext(); ! // } ! ! ! } --- 1,157 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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 a... [truncated message content] |
Update of /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30131/src/org/tmapiutils/query/tolog/test Modified Files: AndClauseTest.java AssociationPredicateTest.java BackendTests.java ImportTest.java Increment.java MemoryQueryEvaluatorImplTest.java NotClauseTest.java OrClauseTest.java ProjectionTest.java RuleTest.java SortingTest.java TologParserTest.java TologParserTestBase.java VariableSetTest.java Log Message: Tabs -> Whitespaces Index: AssociationPredicateTest.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/test/AssociationPredicateTest.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** AssociationPredicateTest.java 9 Mar 2005 12:40:20 -0000 1.4 --- AssociationPredicateTest.java 8 Jul 2005 16:03:21 -0000 1.5 *************** *** 1,216 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.test; ! ! import java.io.StringReader; ! import java.util.ArrayList; ! import java.util.List; ! import java.util.HashMap; ! ! import junit.framework.TestCase; ! ! import org.apache.log4j.BasicConfigurator; ! import org.tmapiutils.query.tolog.parser.ClauseList; ! import org.tmapiutils.query.tolog.parser.PlayerRoleVarPair; ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.predicates.DynamicAssociationPredicate; ! import org.tmapiutils.query.tolog.utils.TologContext; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! // TMAPI ! import org.tmapi.core.Locator; ! import org.tmapi.core.TopicMapSystemFactory; ! import org.tmapi.core.TopicMapSystem; ! import org.tmapi.core.TopicMapObject; ! import org.tmapi.core.TopicMap; ! import org.tmapi.core.Topic; ! import org.tmapi.core.Association; ! ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class AssociationPredicateTest extends TestCase { ! ! private TopicMap m_tm; ! private TopicMapSystem _tmSystem; ! private HashMap _objectMap; ! ! /** ! * Constructor for AssociationPredicateTest. ! * @param arg0 ! */ ! public AssociationPredicateTest(String arg0) { ! super(arg0); ! } ! ! public static void main(String[] args) { ! junit.textui.TestRunner.run(AssociationPredicateTest.class); ! BasicConfigurator.configure(); ! } ! ! public void testSimpleMatch() throws Exception { ! ! ClauseList c = new ClauseList(); ! DynamicAssociationPredicate p = new DynamicAssociationPredicate(); ! ArrayList params = new ArrayList(); ! params.add(m_tm.getObjectById("worksfor")); ! params.add(new PlayerRoleVarPair((Topic) getObjectById("kal"), (Topic) getObjectById("employee"))); ! params.add(new PlayerRoleVarPair(new Variable("A"), (Topic) getObjectById("employer"))); ! p.setParameters(params); ! c.addPredicate(p); ! VariableSet varsIn = new VariableSet(); ! varsIn.addColumn(new Variable("A")); ! varsIn.addRow(varsIn.getColumns()); ! VariableSet varsOut = c.execute(varsIn, new TologContext()); ! assertEquals(1, varsOut.size()); ! List row = varsOut.getRow(0); ! assertNotNull(row); ! assertEquals(row.size(), 1); ! assertEquals(getObjectById("techquila"), row.get(0)); ! ! } ! ! public void testMultipleMatch() throws Exception { ! ! ClauseList c = new ClauseList(); ! DynamicAssociationPredicate p = new DynamicAssociationPredicate(); ! p.initialise(m_tm); ! ArrayList params = new ArrayList(); ! params.add(m_tm.getObjectById("worksfor")); ! params.add(new PlayerRoleVarPair(new Variable("PERSON"), (Topic) getObjectById("employee"))); ! params.add(new PlayerRoleVarPair(new Variable("COMPANY"), (Topic) getObjectById("employer"))); ! p.setParameters(params); ! c.addPredicate(p); ! VariableSet varsIn = new VariableSet(); ! varsIn.addColumn(new Variable("PERSON")); ! varsIn.addColumn(new Variable("COMPANY")); ! varsIn.addRow(varsIn.getColumns()); ! VariableSet varsOut = c.execute(varsIn, new TologContext()); ! assertEquals(2, varsOut.size()); ! for (int i = 0; i < 2; i++) { ! List row = varsOut.getRow(i); ! assertNotNull(row); ! assertEquals(row.size(), 2); ! assertTrue( ! row.get(0).equals(getObjectById("kal")) || ! row.get(0).equals(getObjectById("fred"))); ! assertTrue( ! row.get(1).equals(getObjectById("techquila")) || ! row.get(1).equals(getObjectById("bigcorp"))); ! } ! } ! ! public void testRoleMatch() throws Exception { ! ClauseList c = new ClauseList(); ! DynamicAssociationPredicate p = new DynamicAssociationPredicate(); ! p.initialise(m_tm); ! ArrayList params = new ArrayList(); ! params.add(new Variable("ASSOC")); ! params.add(new PlayerRoleVarPair(new Variable("PERSON"), (Topic) getObjectById("employee"))); ! params.add(new PlayerRoleVarPair(new Variable("COMPANY"), (Topic) getObjectById("employer"))); ! p.setParameters(params); ! c.addPredicate(p); ! VariableSet varsIn = new VariableSet(); ! varsIn.addColumn(new Variable("ASSOC")); ! varsIn.addColumn(new Variable("PERSON")); ! varsIn.addColumn(new Variable("COMPANY")); ! varsIn.addRow(varsIn.getColumns()); ! VariableSet varsOut = c.execute(varsIn, new TologContext()); ! assertEquals(2, varsOut.size()); ! for (int i = 0; i < 2; i++) { ! List row = varsOut.getRow(i); ! assertNotNull(row); ! assertEquals(row.size(), 3); ! assertEquals(row.get(0), getObjectById("worksfor")); ! assertTrue( ! row.get(1).equals(getObjectById("kal")) || ! row.get(1).equals(getObjectById("fred"))); ! assertTrue( ! row.get(2).equals(getObjectById("techquila")) || ! row.get(2).equals(getObjectById("bigcorp"))); ! } ! } ! ! protected void setUp() throws Exception { ! super.setUp(); ! _objectMap = new HashMap(); ! _tmSystem = TopicMapSystemFactory.newInstance().newTopicMapSystem(); ! m_tm = _tmSystem.createTopicMap("http://tmapiutils.org/test/tolog1.0/"); ! createTestMap(m_tm); ! // TopicMapProviderFactory tmpf = new TopicMapProviderFactoryImpl(); ! // m_provider = tmpf.newTopicMapProvider(); ! // Locator loc = m_provider.getLocatorFactory().createLocator("URI", "http://www.techquila.com/test/tolog1.0.xtm"); ! // SerializedTopicMapSource src = new SerializedTopicMapSource(new StringReader(TESTMAP), loc, new LTMBuilder()); ! // m_tm = m_provider.addTopicMap(src); ! } ! ! protected void tearDown() throws Exception{ ! super.tearDown(); ! _objectMap.clear(); ! // remove created TopicMaps from TopicMapSystem ! m_tm.remove(); ! // Close TopicMapSystem instance ! _tmSystem.close(); ! } ! ! public void createTestMap(TopicMap tm) { ! Topic works_for = tm.createTopic(); ! Topic fred = tm.createTopic(); ! Topic kal = tm.createTopic(); ! Topic techquila = tm.createTopic(); ! Topic employee = tm.createTopic(); ! Topic employer = tm.createTopic(); ! Topic bigco = tm.createTopic(); ! ! Association assoc1 = tm.createAssociation(); ! assoc1.setType(works_for); ! assoc1.createAssociationRole(kal, employee); ! assoc1.createAssociationRole(techquila, employer); ! ! ! Association assoc2 = tm.createAssociation(); ! assoc2.setType(works_for); ! assoc2.createAssociationRole(fred, employee); ! assoc2.createAssociationRole(bigco, employer); ! ! registerObject("works-for", works_for); ! registerObject("fred", fred); ! registerObject("kal", kal); ! registerObject("techquila", techquila); ! registerObject("employee", employee); ! registerObject("bigco", bigco); ! registerObject("employer", employer); ! } ! ! protected void registerObject(String name, TopicMapObject obj) { ! _objectMap.put(name, obj); ! } ! ! protected TopicMapObject getObjectById(String name) { ! TopicMapObject obj = (TopicMapObject) _objectMap.get(name); ! if (obj == null) { ! throw new RuntimeException("Object Id not found :" + name); ! } ! return obj; ! } ! ! private static final String TESTMAP ="worksfor(kal:employee, techquila:employer)\n" + "worksfor(fred:employee, bigcorp:employer)\n"; ! } ! --- 1,216 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.test; ! ! import java.io.StringReader; ! import java.util.ArrayList; ! import java.util.List; ! import java.util.HashMap; ! ! import junit.framework.TestCase; ! ! import org.apache.log4j.BasicConfigurator; ! import org.tmapiutils.query.tolog.parser.ClauseList; ! import org.tmapiutils.query.tolog.parser.PlayerRoleVarPair; ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.predicates.DynamicAssociationPredicate; ! import org.tmapiutils.query.tolog.utils.TologContext; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! // TMAPI ! import org.tmapi.core.Locator; ! import org.tmapi.core.TopicMapSystemFactory; ! import org.tmapi.core.TopicMapSystem; ! import org.tmapi.core.TopicMapObject; ! import org.tmapi.core.TopicMap; ! import org.tmapi.core.Topic; ! import org.tmapi.core.Association; ! ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class AssociationPredicateTest extends TestCase { ! ! private TopicMap m_tm; ! private TopicMapSystem _tmSystem; ! private HashMap _objectMap; ! ! /** ! * Constructor for AssociationPredicateTest. ! * @param arg0 ! */ ! public AssociationPredicateTest(String arg0) { ! super(arg0); ! } ! ! public static void main(String[] args) { ! junit.textui.TestRunner.run(AssociationPredicateTest.class); ! BasicConfigurator.configure(); ! } ! ! public void testSimpleMatch() throws Exception { ! ! ClauseList c = new ClauseList(); ! DynamicAssociationPredicate p = new DynamicAssociationPredicate(); ! ArrayList params = new ArrayList(); ! params.add(m_tm.getObjectById("worksfor")); ! params.add(new PlayerRoleVarPair((Topic) getObjectById("kal"), (Topic) getObjectById("employee"))); ! params.add(new PlayerRoleVarPair(new Variable("A"), (Topic) getObjectById("employer"))); ! p.setParameters(params); ! c.addPredicate(p); ! VariableSet varsIn = new VariableSet(); ! varsIn.addColumn(new Variable("A")); ! varsIn.addRow(varsIn.getColumns()); ! VariableSet varsOut = c.execute(varsIn, new TologContext()); ! assertEquals(1, varsOut.size()); ! List row = varsOut.getRow(0); ! assertNotNull(row); ! assertEquals(row.size(), 1); ! assertEquals(getObjectById("techquila"), row.get(0)); ! ! } ! ! public void testMultipleMatch() throws Exception { ! ! ClauseList c = new ClauseList(); ! DynamicAssociationPredicate p = new DynamicAssociationPredicate(); ! p.initialise(m_tm); ! ArrayList params = new ArrayList(); ! params.add(m_tm.getObjectById("worksfor")); ! params.add(new PlayerRoleVarPair(new Variable("PERSON"), (Topic) getObjectById("employee"))); ! params.add(new PlayerRoleVarPair(new Variable("COMPANY"), (Topic) getObjectById("employer"))); ! p.setParameters(params); ! c.addPredicate(p); ! VariableSet varsIn = new VariableSet(); ! varsIn.addColumn(new Variable("PERSON")); ! varsIn.addColumn(new Variable("COMPANY")); ! varsIn.addRow(varsIn.getColumns()); ! VariableSet varsOut = c.execute(varsIn, new TologContext()); ! assertEquals(2, varsOut.size()); ! for (int i = 0; i < 2; i++) { ! List row = varsOut.getRow(i); ! assertNotNull(row); ! assertEquals(row.size(), 2); ! assertTrue( ! row.get(0).equals(getObjectById("kal")) || ! row.get(0).equals(getObjectById("fred"))); ! assertTrue( ! row.get(1).equals(getObjectById("techquila")) || ! row.get(1).equals(getObjectById("bigcorp"))); ! } ! } ! ! public void testRoleMatch() throws Exception { ! ClauseList c = new ClauseList(); ! DynamicAssociationPredicate p = new DynamicAssociationPredicate(); ! p.initialise(m_tm); ! ArrayList params = new ArrayList(); ! params.add(new Variable("ASSOC")); ! params.add(new PlayerRoleVarPair(new Variable("PERSON"), (Topic) getObjectById("employee"))); ! params.add(new PlayerRoleVarPair(new Variable("COMPANY"), (Topic) getObjectById("employer"))); ! p.setParameters(params); ! c.addPredicate(p); ! VariableSet varsIn = new VariableSet(); ! varsIn.addColumn(new Variable("ASSOC")); ! varsIn.addColumn(new Variable("PERSON")); ! varsIn.addColumn(new Variable("COMPANY")); ! varsIn.addRow(varsIn.getColumns()); ! VariableSet varsOut = c.execute(varsIn, new TologContext()); ! assertEquals(2, varsOut.size()); ! for (int i = 0; i < 2; i++) { ! List row = varsOut.getRow(i); ! assertNotNull(row); ! assertEquals(row.size(), 3); ! assertEquals(row.get(0), getObjectById("worksfor")); ! assertTrue( ! row.get(1).equals(getObjectById("kal")) || ! row.get(1).equals(getObjectById("fred"))); ! assertTrue( ! row.get(2).equals(getObjectById("techquila")) || ! row.get(2).equals(getObjectById("bigcorp"))); ! } ! } ! ! protected void setUp() throws Exception { ! super.setUp(); ! _objectMap = new HashMap(); ! _tmSystem = TopicMapSystemFactory.newInstance().newTopicMapSystem(); ! m_tm = _tmSystem.createTopicMap("http://tmapiutils.org/test/tolog1.0/"); ! createTestMap(m_tm); ! // TopicMapProviderFactory tmpf = new TopicMapProviderFactoryImpl(); ! // m_provider = tmpf.newTopicMapProvider(); ! // Locator loc = m_provider.getLocatorFactory().createLocator("URI", "http://www.techquila.com/test/tolog1.0.xtm"); ! // SerializedTopicMapSource src = new SerializedTopicMapSource(new StringReader(TESTMAP), loc, new LTMBuilder()); ! // m_tm = m_provider.addTopicMap(src); ! } ! ! protected void tearDown() throws Exception{ ! super.tearDown(); ! _objectMap.clear(); ! // remove created TopicMaps from TopicMapSystem ! m_tm.remove(); ! // Close TopicMapSystem instance ! _tmSystem.close(); ! } ! ! public void createTestMap(TopicMap tm) { ! Topic works_for = tm.createTopic(); ! Topic fred = tm.createTopic(); ! Topic kal = tm.createTopic(); ! Topic techquila = tm.createTopic(); ! Topic employee = tm.createTopic(); ! Topic employer = tm.createTopic(); ! Topic bigco = tm.createTopic(); ! ! Association assoc1 = tm.createAssociation(); ! assoc1.setType(works_for); ! assoc1.createAssociationRole(kal, employee); ! assoc1.createAssociationRole(techquila, employer); ! ! ! Association assoc2 = tm.createAssociation(); ! assoc2.setType(works_for); ! assoc2.createAssociationRole(fred, employee); ! assoc2.createAssociationRole(bigco, employer); ! ! registerObject("works-for", works_for); ! registerObject("fred", fred); ! registerObject("kal", kal); ! registerObject("techquila", techquila); ! registerObject("employee", employee); ! registerObject("bigco", bigco); ! registerObject("employer", employer); ! } ! ! protected void registerObject(String name, TopicMapObject obj) { ! _objectMap.put(name, obj); ! } ! ! protected TopicMapObject getObjectById(String name) { ! TopicMapObject obj = (TopicMapObject) _objectMap.get(name); ! if (obj == null) { ! throw new RuntimeException("Object Id not found :" + name); ! } ! return obj; ! } ! ! private static final String TESTMAP ="worksfor(kal:employee, techquila:employer)\n" + "worksfor(fred:employee, bigcorp:employer)\n"; ! } ! Index: ImportTest.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/test/ImportTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ImportTest.java 8 Mar 2005 12:33:58 -0000 1.2 --- ImportTest.java 8 Jul 2005 16:03:21 -0000 1.3 *************** *** 1,79 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.test; ! ! import java.io.File; ! import java.io.StringReader; ! import java.util.Map; ! ! import org.tmapiutils.query.tolog.parser.TologLexer; ! import org.tmapiutils.query.tolog.parser.TologParser; ! import org.tmapiutils.query.tolog.parser.TologRule; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class ImportTest extends TologParserTestBase ! { ! File m_modulesDir; ! ! /** ! * @param arg0 ! */ ! public ImportTest(String arg0) { ! super(arg0); ! String testdir = System.getProperty("testdir"); ! m_modulesDir = new File(testdir + File.separator + "tologx"); ! } ! ! public void testImport() throws Exception { ! File refModule = new File(m_modulesDir, "module1.tl"); ! assertTrue("Cannot locate module to be referenced at " + refModule.getAbsolutePath(), ! refModule.exists()); ! ! String rootModule = "import \"" + refModule.toURL().toString() + "\" as test"; ! TologParser p = new TologParser(new TologLexer(new StringReader(rootModule))); ! p.setTopicMap(m_tm); ! p.module(); ! Map rules = p.getRules(); ! assertNotNull(rules); ! assertEquals(1, rules.size()); ! TologRule r = (TologRule)rules.get("test:nestedin"); ! assertNotNull(r); ! } ! ! public void testNestedImport() throws Exception { ! File refModule = new File(m_modulesDir, "nested-module-parent.tl"); ! assertTrue("Cannot locate module to be referenced at " + refModule.getAbsolutePath(), ! refModule.exists()); ! ! String rootModule = "import \"" + refModule.toURL().toString() + "\" as test"; ! TologParser p = new TologParser(new TologLexer(new StringReader(rootModule))); ! p.setTopicMap(m_tm); ! p.module(); ! Map rules = p.getRules(); ! assertNotNull(rules); ! assertEquals(1, rules.size()); ! TologRule r = (TologRule)rules.get("test:crosscontinent"); ! assertNotNull(r); ! } ! ! } ! --- 1,79 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.test; ! ! import java.io.File; ! import java.io.StringReader; ! import java.util.Map; ! ! import org.tmapiutils.query.tolog.parser.TologLexer; ! import org.tmapiutils.query.tolog.parser.TologParser; ! import org.tmapiutils.query.tolog.parser.TologRule; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class ImportTest extends TologParserTestBase ! { ! File m_modulesDir; ! ! /** ! * @param arg0 ! */ ! public ImportTest(String arg0) { ! super(arg0); ! String testdir = System.getProperty("testdir"); ! m_modulesDir = new File(testdir + File.separator + "tologx"); ! } ! ! public void testImport() throws Exception { ! File refModule = new File(m_modulesDir, "module1.tl"); ! assertTrue("Cannot locate module to be referenced at " + refModule.getAbsolutePath(), ! refModule.exists()); ! ! String rootModule = "import \"" + refModule.toURL().toString() + "\" as test"; ! TologParser p = new TologParser(new TologLexer(new StringReader(rootModule))); ! p.setTopicMap(m_tm); ! p.module(); ! Map rules = p.getRules(); ! assertNotNull(rules); ! assertEquals(1, rules.size()); ! TologRule r = (TologRule)rules.get("test:nestedin"); ! assertNotNull(r); ! } ! ! public void testNestedImport() throws Exception { ! File refModule = new File(m_modulesDir, "nested-module-parent.tl"); ! assertTrue("Cannot locate module to be referenced at " + refModule.getAbsolutePath(), ! refModule.exists()); ! ! String rootModule = "import \"" + refModule.toURL().toString() + "\" as test"; ! TologParser p = new TologParser(new TologLexer(new StringReader(rootModule))); ! p.setTopicMap(m_tm); ! p.module(); ! Map rules = p.getRules(); ! assertNotNull(rules); ! assertEquals(1, rules.size()); ! TologRule r = (TologRule)rules.get("test:crosscontinent"); ! assertNotNull(r); ! } ! ! } ! Index: RuleTest.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/test/RuleTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RuleTest.java 8 Mar 2005 12:33:58 -0000 1.2 --- RuleTest.java 8 Jul 2005 16:03:21 -0000 1.3 *************** *** 1,100 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.test; ! ! import java.util.ArrayList; ! import java.util.List; ! ! import junit.framework.TestCase; ! ! import org.apache.log4j.BasicConfigurator; ! import org.tmapiutils.query.tolog.parser.ClauseList; ! import org.tmapiutils.query.tolog.parser.Predicate; ! import org.tmapiutils.query.tolog.parser.TologRule; ! import org.tmapiutils.query.tolog.parser.TologRuleImpl; ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.utils.TologContext; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class RuleTest extends TestCase { ! ! /** ! * Constructor for RuleTest. ! * @param arg0 ! */ ! public RuleTest(String arg0) { ! super(arg0); ! BasicConfigurator.configure(); ! } ! ! public static void main(String[] args) { ! junit.textui.TestRunner.run(RuleTest.class); ! } ! ! public void testRule() throws Exception ! { ! TologRule r = new TologRuleImpl(); ! r.setName("MyRule"); ! r.addHeadParameter(new Variable("A")); ! r.addHeadParameter(new Variable("B")); ! ClauseList ruleBody = new ClauseList(); ! ! Increment i1 = new Increment(); ! ArrayList i1Params = new ArrayList(); ! i1Params.add(new Variable("A")); ! i1Params.add(new Variable("C")); ! i1.setParameters(i1Params); ! ! Increment i2 = new Increment(); ! ArrayList i2Params = new ArrayList(); ! i2Params.add(new Variable("C")); ! i2Params.add(new Variable("B")); ! i2.setParameters(i2Params); ! ! ruleBody.addPredicate(i1); ! ruleBody.addPredicate(i2); ! ! r.setRuleBody(ruleBody); ! ! ClauseList cl = new ClauseList(); ! Predicate p = r.newInstance(); ! ArrayList pParams = new ArrayList(); ! pParams.add(new Integer(1)); ! pParams.add(new Variable("X")); ! p.setParameters(pParams); ! cl.addPredicate(p); ! ! VariableSet vsIn = new VariableSet(); ! vsIn.addColumn(new Variable("X")); ! vsIn.addRow(vsIn.getColumns()); ! VariableSet vsOut = cl.execute(vsIn, new TologContext()); ! assertNotNull(vsOut); ! assertEquals(1, vsOut.size()); ! List row = vsOut.getRow(0); ! assertNotNull(row); ! assertEquals(1, row.size()); ! assertEquals(new Integer(3), row.get(0)); ! } ! ! } ! --- 1,100 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.test; ! ! import java.util.ArrayList; ! import java.util.List; ! ! import junit.framework.TestCase; ! ! import org.apache.log4j.BasicConfigurator; ! import org.tmapiutils.query.tolog.parser.ClauseList; ! import org.tmapiutils.query.tolog.parser.Predicate; ! import org.tmapiutils.query.tolog.parser.TologRule; ! import org.tmapiutils.query.tolog.parser.TologRuleImpl; ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.utils.TologContext; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class RuleTest extends TestCase { ! ! /** ! * Constructor for RuleTest. ! * @param arg0 ! */ ! public RuleTest(String arg0) { ! super(arg0); ! BasicConfigurator.configure(); ! } ! ! public static void main(String[] args) { ! junit.textui.TestRunner.run(RuleTest.class); ! } ! ! public void testRule() throws Exception ! { ! TologRule r = new TologRuleImpl(); ! r.setName("MyRule"); ! r.addHeadParameter(new Variable("A")); ! r.addHeadParameter(new Variable("B")); ! ClauseList ruleBody = new ClauseList(); ! ! Increment i1 = new Increment(); ! ArrayList i1Params = new ArrayList(); ! i1Params.add(new Variable("A")); ! i1Params.add(new Variable("C")); ! i1.setParameters(i1Params); ! ! Increment i2 = new Increment(); ! ArrayList i2Params = new ArrayList(); ! i2Params.add(new Variable("C")); ! i2Params.add(new Variable("B")); ! i2.setParameters(i2Params); ! ! ruleBody.addPredicate(i1); ! ruleBody.addPredicate(i2); ! ! r.setRuleBody(ruleBody); ! ! ClauseList cl = new ClauseList(); ! Predicate p = r.newInstance(); ! ArrayList pParams = new ArrayList(); ! pParams.add(new Integer(1)); ! pParams.add(new Variable("X")); ! p.setParameters(pParams); ! cl.addPredicate(p); ! ! VariableSet vsIn = new VariableSet(); ! vsIn.addColumn(new Variable("X")); ! vsIn.addRow(vsIn.getColumns()); ! VariableSet vsOut = cl.execute(vsIn, new TologContext()); ! assertNotNull(vsOut); ! assertEquals(1, vsOut.size()); ! List row = vsOut.getRow(0); ! assertNotNull(row); ! assertEquals(1, row.size()); ! assertEquals(new Integer(3), row.get(0)); ! } ! ! } ! Index: SortingTest.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/test/SortingTest.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** SortingTest.java 9 Mar 2005 12:40:20 -0000 1.4 --- SortingTest.java 8 Jul 2005 16:03:21 -0000 1.5 *************** *** 1,197 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.test; ! ! import java.util.ArrayList; ! import java.util.HashMap; ! import java.util.Arrays; ! ! import junit.framework.TestCase; ! ! import org.tmapiutils.query.tolog.parser.Sorting; ! import org.tmapiutils.query.tolog.parser.Variable; ! ! // TMAPI ! import org.tmapi.core.TopicMapSystemFactory; ! import org.tmapi.core.TopicMapSystem; ! import org.tmapi.core.TopicMap; ! import org.tmapi.core.Topic; ! import org.tmapi.core.TopicName; ! ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class SortingTest extends TestCase { ! ! private TopicMapSystem _tmSystem; ! ! /** ! * Constructor for SortingTest. ! * @param arg0 ! */ ! public SortingTest(String arg0) throws Exception { ! super(arg0); ! _tmSystem = TopicMapSystemFactory.newInstance().newTopicMapSystem(); ! } ! ! public static void main(String[] args) { ! junit.textui.TestRunner.run(SortingTest.class); ! } ! ! public void testSortIntegers() throws Exception { ! ArrayList cols = new ArrayList(); ! cols.add(new Variable("A")); ! cols.add(new Variable("B")); ! ! ArrayList rows = new ArrayList(); ! ! ArrayList row1 = new ArrayList(); ! row1.add(new Integer(2)); ! row1.add(new Integer(1)); ! rows.add(row1); ! ! ArrayList row2 = new ArrayList(); ! row2.add(new Integer(1)); ! row2.add(new Integer(2)); ! rows.add(row2); ! ! ArrayList row3 = new ArrayList(); ! row3.add(new Integer(1)); ! row3.add(new Integer(1)); ! rows.add(row3); ! ! Sorting sorting = new Sorting(); ! sorting.addSort(new Variable("A")); ! sorting.addSort(new Variable("B")); ! sorting.sort(cols, rows); ! ! assertEquals(row3, rows.get(0)); ! assertEquals(row2, rows.get(1)); ! assertEquals(row1, rows.get(2)); ! } ! ! public void testSortTopics() throws Exception { ! // TopicMap tm = newTopicMap(); ! // Topic t1 = tm.createTopic("t1"); ! // Topic t2 = tm.createTopic("t2"); ! // Topic t3 = tm.createTopic("t3"); ! ! TopicMap tm = _tmSystem.createTopicMap("http://tmapiutils.org/test/tolog1.0/test/SortTopics"); ! Topic t1 = tm.createTopic(); ! Topic t2 = tm.createTopic(); ! Topic t3 = tm.createTopic(); ! ! String[] objectIds = new String[3]; ! objectIds[0] = t1.getObjectId(); ! objectIds[1] = t2.getObjectId(); ! objectIds[2] = t3.getObjectId(); ! Arrays.sort(objectIds); ! ! HashMap topics = new HashMap(); ! topics.put(t1.getObjectId(), t1); ! topics.put(t2.getObjectId(), t2); ! topics.put(t3.getObjectId(), t3); ! ! ArrayList cols = new ArrayList(); ! cols.add(new Variable("A")); ! ArrayList rows = new ArrayList(); ! ! ArrayList row1 = new ArrayList(); ! //row1.add(t3); ! row1.add(topics.get(objectIds[2])); ! rows.add(row1); ! ! ArrayList row2 = new ArrayList(); ! // row2.add(t1); ! row2.add(topics.get(objectIds[0])); ! rows.add(row2); ! ! ArrayList row3 = new ArrayList(); ! // row3.add(t2); ! row3.add(topics.get(objectIds[1])); ! rows.add(row3); ! ! Sorting sorting = new Sorting(); ! sorting.addSort(new Variable("A")); ! sorting.sort(cols, rows); ! sorting.setSortAscending(true); ! ! assertEquals(row2, rows.get(0)); ! assertEquals(row3, rows.get(1)); ! assertEquals(row1, rows.get(2)); ! ! sorting.setSortAscending(false); ! sorting.sort(cols, rows); ! assertEquals(row1, rows.get(0)); ! assertEquals(row3, rows.get(1)); ! assertEquals(row2, rows.get(2)); ! ! } ! ! public void testSortNames() throws Exception { ! // TopicMap tm = newTopicMap(); ! // Topic t1 = tm.createTopic("t1"); ! // TopicName bn1 = t1.createName("bn1","Topic C"); ! // Topic t2 = tm.createTopic("t2"); ! // TopicName bn2 = t2.createName("bn2", "Topic B"); ! // Topic t3 = tm.createTopic("t3"); ! // TopicName bn3 = t3.createName("bn3", "Topic A"); ! TopicMap tm = _tmSystem.createTopicMap("http://tmapiutils.org/test/tolog1.0/test/SortNames"); ! Topic t1 = tm.createTopic(); ! TopicName bn1 = t1.createTopicName("Topic C", null); ! Topic t2 = tm.createTopic(); ! TopicName bn2 = t2.createTopicName("Topic B", null); ! Topic t3 = tm.createTopic(); ! TopicName bn3 = t3.createTopicName("Topic A", null); ! ! ArrayList cols = new ArrayList(); ! cols.add(new Variable("A")); ! ArrayList rows = new ArrayList(); ! ! ArrayList row1 = new ArrayList(); ! row1.add(bn3); ! rows.add(row1); ! ! ArrayList row2 = new ArrayList(); ! row2.add(bn1); ! rows.add(row2); ! ! ArrayList row3 = new ArrayList(); ! row3.add(bn2); ! rows.add(row3); ! ! Sorting sorting = new Sorting(); ! sorting.addSort(new Variable("A")); ! sorting.sort(cols, rows); ! ! assertEquals(row1, rows.get(0)); ! assertEquals(row3, rows.get(1)); ! assertEquals(row2, rows.get(2)); ! ! ! } ! ! // private TopicMap newTopicMap() throws Exception { ! // Locator loc = m_provider.getLocatorFactory().createLocator("URI", "http://www.tm4j.org/tests/" + m_idgen.getObjectId()); ! // return m_provider.createTopicMap(loc); ! // } ! } ! --- 1,197 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.test; ! ! import java.util.ArrayList; ! import java.util.HashMap; ! import java.util.Arrays; ! ! import junit.framework.TestCase; ! ! import org.tmapiutils.query.tolog.parser.Sorting; ! import org.tmapiutils.query.tolog.parser.Variable; ! ! // TMAPI ! import org.tmapi.core.TopicMapSystemFactory; ! import org.tmapi.core.TopicMapSystem; ! import org.tmapi.core.TopicMap; ! import org.tmapi.core.Topic; ! import org.tmapi.core.TopicName; ! ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class SortingTest extends TestCase { ! ! private TopicMapSystem _tmSystem; ! ! /** ! * Constructor for SortingTest. ! * @param arg0 ! */ ! public SortingTest(String arg0) throws Exception { ! super(arg0); ! _tmSystem = TopicMapSystemFactory.newInstance().newTopicMapSystem(); ! } ! ! public static void main(String[] args) { ! junit.textui.TestRunner.run(SortingTest.class); ! } ! ! public void testSortIntegers() throws Exception { ! ArrayList cols = new ArrayList(); ! cols.add(new Variable("A")); ! cols.add(new Variable("B")); ! ! ArrayList rows = new ArrayList(); ! ! ArrayList row1 = new ArrayList(); ! row1.add(new Integer(2)); ! row1.add(new Integer(1)); ! rows.add(row1); ! ! ArrayList row2 = new ArrayList(); ! row2.add(new Integer(1)); ! row2.add(new Integer(2)); ! rows.add(row2); ! ! ArrayList row3 = new ArrayList(); ! row3.add(new Integer(1)); ! row3.add(new Integer(1)); ! rows.add(row3); ! ! Sorting sorting = new Sorting(); ! sorting.addSort(new Variable("A")); ! sorting.addSort(new Variable("B")); ! sorting.sort(cols, rows); ! ! assertEquals(row3, rows.get(0)); ! assertEquals(row2, rows.get(1)); ! assertEquals(row1, rows.get(2)); ! } ! ! public void testSortTopics() throws Exception { ! // TopicMap tm = newTopicMap(); ! // Topic t1 = tm.createTopic("t1"); ! // Topic t2 = tm.createTopic("t2"); ! // Topic t3 = tm.createTopic("t3"); ! ! TopicMap tm = _tmSystem.createTopicMap("http://tmapiutils.org/test/tolog1.0/test/SortTopics"); ! Topic t1 = tm.createTopic(); ! Topic t2 = tm.createTopic(); ! Topic t3 = tm.createTopic(); ! ! String[] objectIds = new String[3]; ! objectIds[0] = t1.getObjectId(); ! objectIds[1] = t2.getObjectId(); ! objectIds[2] = t3.getObjectId(); ! Arrays.sort(objectIds); ! ! HashMap topics = new HashMap(); ! topics.put(t1.getObjectId(), t1); ! topics.put(t2.getObjectId(), t2); ! topics.put(t3.getObjectId(), t3); ! ! ArrayList cols = new ArrayList(); ! cols.add(new Variable("A")); ! ArrayList rows = new ArrayList(); ! ! ArrayList row1 = new ArrayList(); ! //row1.add(t3); ! row1.add(topics.get(objectIds[2])); ! rows.add(row1); ! ! ArrayList row2 = new ArrayList(); ! // row2.add(t1); ! row2.add(topics.get(objectIds[0])); ! rows.add(row2); ! ! ArrayList row3 = new ArrayList(); ! // row3.add(t2); ! row3.add(topics.get(objectIds[1])); ! rows.add(row3); ! ! Sorting sorting = new Sorting(); ! sorting.addSort(new Variable("A")); ! sorting.sort(cols, rows); ! sorting.setSortAscending(true); ! ! assertEquals(row2, rows.get(0)); ! assertEquals(row3, rows.get(1)); ! assertEquals(row1, rows.get(2)); ! ! sorting.setSortAscending(false); ! sorting.sort(cols, rows); ! assertEquals(row1, rows.get(0)); ! assertEquals(row3, rows.get(1)); ! assertEquals(row2, rows.get(2)); ! ! } ! ! public void testSortNames() throws Exception { ! // TopicMap tm = newTopicMap(); ! // Topic t1 = tm.createTopic("t1"); ! // TopicName bn1 = t1.createName("bn1","Topic C"); ! // Topic t2 = tm.createTopic("t2"); ! // TopicName bn2 = t2.createName("bn2", "Topic B"); ! // Topic t3 = tm.createTopic("t3"); ! // TopicName bn3 = t3.createName("bn3", "Topic A"); ! TopicMap tm = _tmSystem.createTopicMap("http://tmapiutils.org/test/tolog1.0/test/SortNames"); ! Topic t1 = tm.createTopic(); ! TopicName bn1 = t1.createTopicName("Topic C", null); ! Topic t2 = tm.createTopic(); ! TopicName bn2 = t2.createTopicName("Topic B", null); ! Topic t3 = tm.createTopic(); ! TopicName bn3 = t3.createTopicName("Topic A", null); ! ! ArrayList cols = new ArrayList(); ! cols.add(new Variable("A")); ! ArrayList rows = new ArrayList(); ! ! ArrayList row1 = new ArrayList(); ! row1.add(bn3); ! rows.add(row1); ! ! ArrayList row2 = new ArrayList(); ! row2.add(bn1); ! rows.add(row2); ! ! ArrayList row3 = new ArrayList(); ! row3.add(bn2); ! rows.add(row3); ! ! Sorting sorting = new Sorting(); ! sorting.addSort(new Variable("A")); ! sorting.sort(cols, rows); ! ! assertEquals(row1, rows.get(0)); ! assertEquals(row3, rows.get(1)); ! assertEquals(row2, rows.get(2)); ! ! ! } ! ! // private TopicMap newTopicMap() throws Exception { ! // Locator loc = m_provider.getLocatorFactory().createLocator("URI", "http://www.tm4j.org/tests/" + m_idgen.getObjectId()); ! // return m_provider.createTopicMap(loc); ! // } ! } ! Index: ProjectionTest.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/test/ProjectionTest.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ProjectionTest.java 9 Mar 2005 12:40:20 -0000 1.4 --- ProjectionTest.java 8 Jul 2005 16:03:21 -0000 1.5 *************** *** 1,200 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.test; ! ! import java.io.StringReader; ! import java.util.ArrayList; ! import java.util.Iterator; ! import java.util.List; ! import java.util.HashMap; ! ! import junit.framework.TestCase; ! ! import org.tmapiutils.query.tolog.parser.ClauseList; ! import org.tmapiutils.query.tolog.parser.PlayerRoleVarPair; ! import org.tmapiutils.query.tolog.parser.Projection; ! import org.tmapiutils.query.tolog.parser.ProjectionImpl; ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.predicates.DynamicAssociationPredicate; ! import org.tmapiutils.query.tolog.utils.TologContext; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! // TMAPI ! import org.tmapi.core.Locator; ! import org.tmapi.core.TopicMapSystemFactory; ! import org.tmapi.core.TopicMapSystem; ! import org.tmapi.core.TopicMapObject; ! import org.tmapi.core.TopicMap; ! import org.tmapi.core.Topic; ! import org.tmapi.core.Association; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class ProjectionTest extends TestCase { ! ! private TopicMap m_tm; ! private TopicMapSystem _tmSystem; ! private HashMap _objectMap; ! ! /** ! * Constructor for ProjectionTest. ! * @param arg0 ! */ ! public ProjectionTest(String arg0) { ! super(arg0); ! } ! ! public static void main(String[] args) { ! junit.textui.TestRunner.run(ProjectionTest.class); ! } ! ! public void testCount() throws Exception { ! ClauseList c = new ClauseList(); ! DynamicAssociationPredicate p = new DynamicAssociationPredicate(); ! ArrayList params = new ArrayList(); ! params.add(getObjectById("contains")); ! params.add(new PlayerRoleVarPair(new Variable("CONTAINER"), (Topic) getObjectById("container"))); ! params.add(new PlayerRoleVarPair(new Variable("CONTAINEE"), (Topic) getObjectById("containee"))); ! p.setParameters(params); ! p.initialise(m_tm); ! VariableSet varsIn = new VariableSet(); ! varsIn.addColumn(new Variable("CONTAINER")); ! varsIn.addColumn(new Variable("CONTAINEE")); ! varsIn.addRow(varsIn.getColumns()); ! c.addPredicate(p); ! VariableSet varsOut = c.execute(varsIn, new TologContext()); ! assertNotNull(varsOut); ! assertEquals(5, varsOut.size()); ! Projection proj = new ProjectionImpl(); ! proj.addVariable(new Variable("CONTAINER")); ! proj.addCount(new Variable("CONTAINEE")); ! proj.addVariableSet(varsOut); ! List projRows = proj.getRows(); ! assertNotNull(projRows); ! assertEquals(2, projRows.size()); ! Iterator it = projRows.iterator(); ! while (it.hasNext()) { ! List row = (List) it.next(); ! assertNotNull(row); ! assertEquals(2, row.size()); ! assertTrue(row.get(0) instanceof Topic); ! assertTrue(row.get(1) instanceof Integer); ! if (row.get(0).equals(getObjectById("europe"))) { ! assertEquals(new Integer(3), row.get(1)); ! } else if (row.get(0).equals(getObjectById("asia"))) { ! assertEquals(new Integer(2), row.get(1)); ! } ! } ! } ! ! /* ! * @see TestCase#setUp() ! */ ! protected void setUp() throws Exception { ! super.setUp(); ! _objectMap = new HashMap(); ! _tmSystem = TopicMapSystemFactory.newInstance().newTopicMapSystem(); ! m_tm = _tmSystem.createTopicMap("http://tmapiutils.org/test/tolog1.0/"); ! createTestMap(m_tm); ! // TopicMapProviderFactory tmpf = new TopicMapProviderFactoryImpl(); ! // m_provider = tmpf.newTopicMapProvider(); ! // Locator loc = m_provider.getLocatorFactory().createLocator("URI", "http://www.techquila.com/test/tolog1.0.xtm"); ! // SerializedTopicMapSource src = new SerializedTopicMapSource(new StringReader(TESTMAP), loc, new LTMBuilder()); ! // m_tm = m_provider.addTopicMap(src); ! } ! ! protected void tearDown() throws Exception{ ! super.tearDown(); ! _objectMap.clear(); ! // remove created TopicMaps from TopicMapSystem ! m_tm.remove(); ! // Close TopicMapSystem instance ! _tmSystem.close(); ! } ! ! public void createTestMap(TopicMap tm) { ! Topic contains = tm.createTopic(); ! Topic europe = tm.createTopic(); ! Topic container = tm.createTopic(); ! Topic uk = tm.createTopic(); ! Topic containee = tm.createTopic(); ! Topic germany = tm.createTopic(); ! Topic france = tm.createTopic(); ! Topic asia = tm.createTopic(); ! Topic japan = tm.createTopic(); ! Topic india = tm.createTopic(); ! ! Association assoc1 = tm.createAssociation(); ! assoc1.setType(contains); ! assoc1.createAssociationRole(europe, container); ! assoc1.createAssociationRole(germany, containee); ! ! Association assoc2 = tm.createAssociation(); ! assoc2.setType(contains); ! assoc2.createAssociationRole(europe, container); ! assoc2.createAssociationRole(uk, containee); ! ! Association assoc3 = tm.createAssociation(); ! assoc3.setType(contains); ! assoc3.createAssociationRole(europe, container); ! assoc3.createAssociationRole(france, containee); ! ! Association assoc4 = tm.createAssociation(); ! assoc4.setType(contains); ! assoc4.createAssociationRole(asia, container); ! assoc4.createAssociationRole(japan, containee); ! ! Association assoc5 = tm.createAssociation(); ! assoc5.setType(contains); ! assoc5.createAssociationRole(asia, container); ! assoc5.createAssociationRole(india, containee); ! ! registerObject("contains", contains); ! registerObject("container", container); ! registerObject("containee", containee); ! registerObject("europe", europe); ! registerObject("uk", uk); ! registerObject("germany", germany); ! registerObject("france", france); ! registerObject("asia", asia); ! registerObject("japan", japan); ! registerObject("india", india); ! } ! ! protected void registerObject(String name, TopicMapObject obj) { ! _objectMap.put(name, obj); ! } ! ! protected TopicMapObject getObjectById(String name) { ! TopicMapObject obj = (TopicMapObject) _objectMap.get(name); ! if (obj == null) { ! throw new RuntimeException("Object Id not found :" + name); ! } ! return obj; ! } ! ! private static final String TESTMAP = ! "contains(europe:container, uk:containee)\n" + ! "contains(europe:container, germany:containee)\n" + ! "contains(europe:container, france:containee)\n" + ! "contains(asia:container, japan:containee)\n" + ! "contains(asia:container, india:containee)\n"; ! } ! --- 1,200 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.test; ! ! import java.io.StringReader; ! import java.util.ArrayList; ! import java.util.Iterator; ! import java.util.List; ! import java.util.HashMap; ! ! import junit.framework.TestCase; ! ! import org.tmapiutils.query.tolog.parser.ClauseList; ! import org.tmapiutils.query.tolog.parser.PlayerRoleVarPair; ! import org.tmapiutils.query.tolog.parser.Projection; ! import org.tmapiutils.query.tolog.parser.ProjectionImpl; ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.predicates.DynamicAssociationPredicate; ! import org.tmapiutils.query.tolog.utils.TologContext; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! // TMAPI ! import org.tmapi.core.Locator; ! import org.tmapi.core.TopicMapSystemFactory; ! import org.tmapi.core.TopicMapSystem; ! import org.tmapi.core.TopicMapObject; ! import org.tmapi.core.TopicMap; ! import org.tmapi.core.Topic; ! import org.tmapi.core.Association; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class ProjectionTest extends TestCase { ! ! private TopicMap m_tm; ! private TopicMapSystem _tmSystem; ! private HashMap _objectMap; ! ! /** ! * Constructor for ProjectionTest. ! * @param arg0 ! */ ! public ProjectionTest(String arg0) { ! super(arg0); ! } ! ! public static void main(String[] args) { ! junit.textui.TestRunner.run(ProjectionTest.class); ! } ! ! public void testCount() throws Exception { ! ClauseList c = new ClauseList(); ! DynamicAssociationPredicate p = new DynamicAssociationPredicate(); ! ArrayList params = new ArrayList(); ! params.add(getObjectById("contains")); ! params.add(new PlayerRoleVarPair(new Variable("CONTAINER"), (Topic) getObjectById("container"))); ! params.add(new PlayerRoleVarPair(new Variable("CONTAINEE"), (Topic) getObjectById("containee"))); ! p.setParameters(params); ! p.initialise(m_tm); ! VariableSet varsIn = new VariableSet(); ! varsIn.addColumn(new Variable("CONTAINER")); ! varsIn.addColumn(new Variable("CONTAINEE")); ! varsIn.addRow(varsIn.getColumns()); ! c.addPredicate(p); ! VariableSet varsOut = c.execute(varsIn, new TologContext()); ! assertNotNull(varsOut); ! assertEquals(5, varsOut.size()); ! Projection proj = new ProjectionImpl(); ! proj.addVariable(new Variable("CONTAINER")); ! proj.addCount(new Variable("CONTAINEE")); ! proj.addVariableSet(varsOut); ! List projRows = proj.getRows(); ! assertNotNull(projRows); ! assertEquals(2, projRows.size()); ! Iterator it = projRows.iterator(); ! while (it.hasNext()) { ! List row = (List) it.next(); ! assertNotNull(row); ! assertEquals(2, row.size()); ! assertTrue(row.get(0) instanceof Topic); ! assertTrue(row.get(1) instanceof Integer); ! if (row.get(0).equals(getObjectById("europe"))) { ! assertEquals(new Integer(3), row.get(1)); ! } else if (row.get(0).equals(getObjectById("asia"))) { ! assertEquals(new Integer(2), row.get(1)); ! } ! } ! } ! ! /* ! * @see TestCase#setUp() ! */ ! protected void setUp() throws Exception { ! super.setUp(); ! _objectMap = new HashMap(); ! _tmSystem = TopicMapSystemFactory.newInstance().newTopicMapSystem(); ! m_tm = _tmSystem.createTopicMap("http://tmapiutils.org/test/tolog1.0/"); ! createTestMap(m_tm); ! // TopicMapProviderFactory tmpf = new TopicMapProviderFactoryImpl(); ! // m_provider = tmpf.newTopicMapProvider(); ! // Locator loc = m_provider.getLocatorFactory().createLocator("URI", "http://www.techquila.com/test/tolog1.0.xtm"); ! // SerializedTopicMapSource src = new SerializedTopicMapSource(new StringReader(TESTMAP), loc, new LTMBuilder()); ! // m_tm = m_provider.addTopicMap(src); ! } ! ! protected void tearDown() throws Exception{ ! super.tearDown(); ! _objectMap.clear(); ! // remove created TopicMaps from TopicMapSystem ! m_tm.remove(); ! // Close TopicMapSystem instance ! _tmSystem.close(); ! } ! ! public void createTestMap(TopicMap tm) { ! Topic contains = tm.createTopic(); ! Topic europe = tm.createTopic(); ! Topic container = tm.createTopic(); ! Topic uk = tm.createTopic(); ! Topic containee = tm.createTopic(); ! Topic germany = tm.createTopic(); ! Topic france = tm.createTopic(); ! Topic asia = tm.createTopic(); ! Topic japan = tm.createTopic(); ! Topic india = tm.createTopic(); ! ! Association assoc1 = tm.createAssociation(); ! assoc1.setType(contains); ! assoc1.createAssociationRole(europe, container); ! assoc1.createAssociationRole(germany, containee); ! ! Association assoc2 = tm.createAssociation(); ! assoc2.setType(contains); ! assoc2.createAssociationRole(europe, container); ! assoc2.createAssociationRole(uk, containee); ! ! Association assoc3 = tm.createAssociation(); ! assoc3.setType(contains); ! assoc3.createAssociationRole(europe, container); ! assoc3.createAssociationRole(france, containee); ! ! Association assoc4 = tm.createAssociation(); ! assoc4.setType(contains); ! assoc4.createAssociationRole(asia, container); ! assoc4.createAssociationRole(japan, containee); ! ! Association assoc5 = tm.createAssociation(); ! assoc5.setType(contains); ! assoc5.createAssociationRole(asia, container); ! assoc5.createAssociationRole(india, containee); ! ! registerObject("contains", contains); ! registerObject("container", container); ! registerObject("containee", containee); ! registerObject("europe", europe); ! registerObject("uk", uk); ! registerObject("germany", germany); ! registerObject("france", france); ! registerObject("asia", asia); ! registerObject("japan", japan); ! registerObject("india", india); ! } ! ! protected void registerObject(String name, TopicMapObject obj) { ! _objectMap.put(name, obj); ! } ! ! protected TopicMapObject getObjectById(String name) { ! TopicMapObject obj = (TopicMapObject) _objectMap.get(name); ! if (obj == null) { ! throw new RuntimeException("Object Id not found :" + name); ! } ! return obj; ! } ! ! private static final String TESTMAP = ! "contains(europe:container, uk:containee)\n" + ! "contains(europe:container, germany:containee)\n" + ! "contains(europe:container, france:containee)\n" + ! "contains(asia:container... [truncated message content] |
Update of /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/parser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30131/src/org/tmapiutils/query/tolog/parser Modified Files: Clause.java ClauseList.java NEClause.java NotClause.java OrClause.java Placeholder.java PlayerRolePair.java PlayerRoleVarPair.java Predicate.java Projection.java ProjectionImpl.java Sorting.java TologQuery.java TologResultsSetImpl.java TologRule.java TologRuleImpl.java TologRuleInstance.java TologRuleInstanceImpl.java Variable.java Log Message: Tabs -> Whitespaces Index: PlayerRolePair.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/parser/PlayerRolePair.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** PlayerRolePair.java 9 Mar 2005 12:40:18 -0000 1.3 --- PlayerRolePair.java 8 Jul 2005 16:03:19 -0000 1.4 *************** *** 1,47 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.parser; ! ! import org.tmapiutils.query.tolog.utils.ReferenceUtils; ! // TMAPI ! import org.tmapi.core.Topic; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class PlayerRolePair { ! protected Topic m_pTopic; ! protected Topic m_rTopic; ! ! protected PlayerRolePair() { ! } ! public PlayerRolePair(Topic playerTopic, Topic roleTopic) { ! m_pTopic = playerTopic; ! m_rTopic = roleTopic; ! } ! ! public Topic getPlayerTopic() { return m_pTopic; } ! public Topic getRoleTopic() { return m_rTopic; } ! ! public String toString() { ! return ReferenceUtils.getTologReference(m_pTopic) + ":" + ReferenceUtils.getTologReference(m_rTopic); ! } ! } ! --- 1,47 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.parser; ! ! import org.tmapiutils.query.tolog.utils.ReferenceUtils; ! // TMAPI ! import org.tmapi.core.Topic; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class PlayerRolePair { ! protected Topic m_pTopic; ! protected Topic m_rTopic; ! ! protected PlayerRolePair() { ! } ! public PlayerRolePair(Topic playerTopic, Topic roleTopic) { ! m_pTopic = playerTopic; ! m_rTopic = roleTopic; ! } ! ! public Topic getPlayerTopic() { return m_pTopic; } ! public Topic getRoleTopic() { return m_rTopic; } ! ! public String toString() { ! return ReferenceUtils.getTologReference(m_pTopic) + ":" + ReferenceUtils.getTologReference(m_rTopic); ! } ! } ! Index: TologRuleImpl.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/parser/TologRuleImpl.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TologRuleImpl.java 8 Mar 2005 12:33:40 -0000 1.2 --- TologRuleImpl.java 8 Jul 2005 16:03:19 -0000 1.3 *************** *** 1,98 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.parser; ! ! import java.util.ArrayList; ! import java.util.Iterator; ! import java.util.List; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class TologRuleImpl implements TologRule { ! ! private ClauseList m_body; ! ! private List m_headParams; ! ! private String m_name; ! ! public TologRuleImpl() { ! m_headParams = new ArrayList(); ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.Rule#getName() ! */ ! public String getName() { ! return m_name; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.Rule#setName(java.lang.String) ! */ ! public void setName(String name) { ! m_name = name; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.Rule#addParam(org.tmapiutils.query.tolog.Variable) ! */ ! public void addHeadParameter(Variable param) { ! m_headParams.add(param); ! } ! ! public void setRuleBody(ClauseList body) { ! m_body = body; ! } ! ! public ClauseList getRuleBody() { ! return m_body; ! } ! ! public List getHeadParameters() { ! return m_headParams; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.Rule#newInstance() ! */ ! public TologRuleInstance newInstance() { ! return new TologRuleInstanceImpl(this); ! } ! ! public String toString() { ! StringBuffer ret = new StringBuffer(); ! ret.append(getName()); ! ret.append("("); ! Iterator it = m_headParams.iterator(); ! while (it.hasNext()) { ! ret.append(it.next().toString()); ! if (it.hasNext()) { ! ret.append(", "); ! } ! } ! ret.append(") :- "); ! ret.append(m_body.toString()); ! ret.append("."); ! return ret.toString(); ! } ! } ! --- 1,98 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.parser; ! ! import java.util.ArrayList; ! import java.util.Iterator; ! import java.util.List; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class TologRuleImpl implements TologRule { ! ! private ClauseList m_body; ! ! private List m_headParams; ! ! private String m_name; ! ! public TologRuleImpl() { ! m_headParams = new ArrayList(); ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.Rule#getName() ! */ ! public String getName() { ! return m_name; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.Rule#setName(java.lang.String) ! */ ! public void setName(String name) { ! m_name = name; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.Rule#addParam(org.tmapiutils.query.tolog.Variable) ! */ ! public void addHeadParameter(Variable param) { ! m_headParams.add(param); ! } ! ! public void setRuleBody(ClauseList body) { ! m_body = body; ! } ! ! public ClauseList getRuleBody() { ! return m_body; ! } ! ! public List getHeadParameters() { ! return m_headParams; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.Rule#newInstance() ! */ ! public TologRuleInstance newInstance() { ! return new TologRuleInstanceImpl(this); ! } ! ! public String toString() { ! StringBuffer ret = new StringBuffer(); ! ret.append(getName()); ! ret.append("("); ! Iterator it = m_headParams.iterator(); ! while (it.hasNext()) { ! ret.append(it.next().toString()); ! if (it.hasNext()) { ! ret.append(", "); ! } ! } ! ret.append(") :- "); ! ret.append(m_body.toString()); ! ret.append("."); ! return ret.toString(); ! } ! } ! Index: TologQuery.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/parser/TologQuery.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TologQuery.java 8 Mar 2005 12:33:40 -0000 1.2 --- TologQuery.java 8 Jul 2005 16:03:19 -0000 1.3 *************** *** 1,176 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.parser; ! ! import java.util.List; ! ! import org.apache.commons.logging.Log; ! import org.apache.commons.logging.LogFactory; ! import org.tmapiutils.query.tolog.TologResultsSet; ! import org.tmapiutils.query.tolog.TologProcessingException; ! import org.tmapiutils.query.tolog.utils.TologContext; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class TologQuery { ! ! private ClauseList m_rootClauseList; ! private Projection m_projection; ! private Sorting m_sorting; ! private int m_pageStart; ! private int m_pageLength; ! private static final Log m_log = LogFactory.getLog(TologQuery.class); ! ! public TologQuery(ClauseList rootClauseList) { ! m_rootClauseList = rootClauseList; ! } ! ! public ClauseList getRootClauseList() { ! return m_rootClauseList; ! } ! ! /** ! * @return ! */ ! public Projection getProjection() { ! return m_projection; ! } ! ! /** ! * @param projection ! */ ! public void setProjection(Projection projection) { ! m_projection = projection; ! } ! ! /** ! * @return ! */ ! public Sorting getSorting() { ! return m_sorting; ! } ! ! /** ! * @param sorting ! */ ! public void setSorting(Sorting sorting) { ! m_sorting = sorting; ! } ! ! ! /** ! * @return ! */ ! public int getPageLength() { ! return m_pageLength; ! } ! ! /** ! * @return ! */ ! public int getPageStart() { ! return m_pageStart; ! } ! ! /** ! * @param i ! */ ! public void setPageLength(int i) { ! m_pageLength = i; ! } ! ! /** ! * @param i ! */ ! public void setPageStart(int i) { ! m_pageStart = i; ! } ! ! public TologResultsSet execute() throws TologProcessingException { ! TologContext context = new TologContext(); ! VariableSet varsIn = new VariableSet(); ! //varsIn.append(new HashMap()); ! //varsIn.addColumns(m_projection.getColumns()); ! //varsIn.addRow(m_projection.getColumns()); ! varsIn.addColumns(m_rootClauseList.getVariables()); ! varsIn.addRow(varsIn.getColumns()); ! VariableSet varsOut = m_rootClauseList.execute(varsIn, context); ! m_log.debug("Root clause evaluation returned " + varsOut.size() + " mappings."); ! m_projection.addVariableSet(varsOut); ! m_log.debug("After projection, row count = " + m_projection.getRows().size()); ! List sortedRows = m_sorting == null ? m_projection.getRows() : m_sorting.sort(m_projection.getColumns(), m_projection.getRows()); ! m_log.debug("After sort, row count = " + sortedRows.size()); ! int pageLength = m_pageLength == 0 ? sortedRows.size() - m_pageStart : m_pageLength; ! m_log.debug("Selecting sublist from " + m_pageStart + " for "+ pageLength + " rows"); ! return new TologResultsSetImpl(m_projection.getColumns(), sortedRows.subList(m_pageStart, pageLength)); ! } ! ! public String toString() { ! StringBuffer sb = new StringBuffer(); ! if (m_projection != null) { ! sb.append(m_projection.toString()); ! sb.append(" "); ! } ! sb.append(m_rootClauseList.toString()); ! if (m_sorting != null) { ! sb.append(" "); ! sb.append(m_sorting.toString()); ! sb.append(" "); ! } ! if (m_pageLength > 0) { ! sb.append(" limit "); ! sb.append(m_pageLength); ! sb.append(" "); ! } ! if (m_pageStart > 0) { ! sb.append("offset "); ! sb.append(m_pageStart); ! sb.append(" "); ! } ! sb.append("?"); ! return sb.toString(); ! } ! ! /** ! * @param params ! * @return ! */ ! public TologResultsSet execute(Object[] params) throws TologProcessingException { ! TologContext context = new TologContext(); ! VariableSet varsIn = new VariableSet(); ! varsIn.addColumns(m_rootClauseList.getVariables()); ! varsIn.addRow(varsIn.getColumns()); ! m_rootClauseList.doReplacement(params); ! VariableSet varsOut = m_rootClauseList.execute(varsIn, context); ! m_log.debug("Root clause evaluation returned " + varsOut.size() + " mappings."); ! m_projection.addVariableSet(varsOut); ! m_log.debug("After projection, row count = " + m_projection.getRows().size()); ! List sortedRows = m_sorting == null ? m_projection.getRows() : m_sorting.sort(m_projection.getColumns(), m_projection.getRows()); ! m_log.debug("After sort, row count = " + sortedRows.size()); ! int pageLength = m_pageLength == 0 ? sortedRows.size() - m_pageStart : m_pageLength; ! m_log.debug("Selecting sublist from " + m_pageStart + " for "+ pageLength + " rows"); ! return new TologResultsSetImpl(m_projection.getColumns(), sortedRows.subList(m_pageStart, pageLength)); ! } ! ! ! } ! --- 1,176 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.parser; ! ! import java.util.List; ! ! import org.apache.commons.logging.Log; ! import org.apache.commons.logging.LogFactory; ! import org.tmapiutils.query.tolog.TologResultsSet; ! import org.tmapiutils.query.tolog.TologProcessingException; ! import org.tmapiutils.query.tolog.utils.TologContext; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class TologQuery { ! ! private ClauseList m_rootClauseList; ! private Projection m_projection; ! private Sorting m_sorting; ! private int m_pageStart; ! private int m_pageLength; ! private static final Log m_log = LogFactory.getLog(TologQuery.class); ! ! public TologQuery(ClauseList rootClauseList) { ! m_rootClauseList = rootClauseList; ! } ! ! public ClauseList getRootClauseList() { ! return m_rootClauseList; ! } ! ! /** ! * @return ! */ ! public Projection getProjection() { ! return m_projection; ! } ! ! /** ! * @param projection ! */ ! public void setProjection(Projection projection) { ! m_projection = projection; ! } ! ! /** ! * @return ! */ ! public Sorting getSorting() { ! return m_sorting; ! } ! ! /** ! * @param sorting ! */ ! public void setSorting(Sorting sorting) { ! m_sorting = sorting; ! } ! ! ! /** ! * @return ! */ ! public int getPageLength() { ! return m_pageLength; ! } ! ! /** ! * @return ! */ ! public int getPageStart() { ! return m_pageStart; ! } ! ! /** ! * @param i ! */ ! public void setPageLength(int i) { ! m_pageLength = i; ! } ! ! /** ! * @param i ! */ ! public void setPageStart(int i) { ! m_pageStart = i; ! } ! ! public TologResultsSet execute() throws TologProcessingException { ! TologContext context = new TologContext(); ! VariableSet varsIn = new VariableSet(); ! //varsIn.append(new HashMap()); ! //varsIn.addColumns(m_projection.getColumns()); ! //varsIn.addRow(m_projection.getColumns()); ! varsIn.addColumns(m_rootClauseList.getVariables()); ! varsIn.addRow(varsIn.getColumns()); ! VariableSet varsOut = m_rootClauseList.execute(varsIn, context); ! m_log.debug("Root clause evaluation returned " + varsOut.size() + " mappings."); ! m_projection.addVariableSet(varsOut); ! m_log.debug("After projection, row count = " + m_projection.getRows().size()); ! List sortedRows = m_sorting == null ? m_projection.getRows() : m_sorting.sort(m_projection.getColumns(), m_projection.getRows()); ! m_log.debug("After sort, row count = " + sortedRows.size()); ! int pageLength = m_pageLength == 0 ? sortedRows.size() - m_pageStart : m_pageLength; ! m_log.debug("Selecting sublist from " + m_pageStart + " for "+ pageLength + " rows"); ! return new TologResultsSetImpl(m_projection.getColumns(), sortedRows.subList(m_pageStart, pageLength)); ! } ! ! public String toString() { ! StringBuffer sb = new StringBuffer(); ! if (m_projection != null) { ! sb.append(m_projection.toString()); ! sb.append(" "); ! } ! sb.append(m_rootClauseList.toString()); ! if (m_sorting != null) { ! sb.append(" "); ! sb.append(m_sorting.toString()); ! sb.append(" "); ! } ! if (m_pageLength > 0) { ! sb.append(" limit "); ! sb.append(m_pageLength); ! sb.append(" "); ! } ! if (m_pageStart > 0) { ! sb.append("offset "); ! sb.append(m_pageStart); ! sb.append(" "); ! } ! sb.append("?"); ! return sb.toString(); ! } ! ! /** ! * @param params ! * @return ! */ ! public TologResultsSet execute(Object[] params) throws TologProcessingException { ! TologContext context = new TologContext(); ! VariableSet varsIn = new VariableSet(); ! varsIn.addColumns(m_rootClauseList.getVariables()); ! varsIn.addRow(varsIn.getColumns()); ! m_rootClauseList.doReplacement(params); ! VariableSet varsOut = m_rootClauseList.execute(varsIn, context); ! m_log.debug("Root clause evaluation returned " + varsOut.size() + " mappings."); ! m_projection.addVariableSet(varsOut); ! m_log.debug("After projection, row count = " + m_projection.getRows().size()); ! List sortedRows = m_sorting == null ? m_projection.getRows() : m_sorting.sort(m_projection.getColumns(), m_projection.getRows()); ! m_log.debug("After sort, row count = " + sortedRows.size()); ! int pageLength = m_pageLength == 0 ? sortedRows.size() - m_pageStart : m_pageLength; ! m_log.debug("Selecting sublist from " + m_pageStart + " for "+ pageLength + " rows"); ! return new TologResultsSetImpl(m_projection.getColumns(), sortedRows.subList(m_pageStart, pageLength)); ! } ! ! ! } ! Index: Variable.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/parser/Variable.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Variable.java 8 Mar 2005 12:33:40 -0000 1.2 --- Variable.java 8 Jul 2005 16:03:20 -0000 1.3 *************** *** 1,48 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.parser; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class Variable { ! ! private String m_name; ! public Variable(String name) { ! m_name = name; ! } ! public String getName() { return m_name; } ! ! public String toString() { ! return "$" + m_name; ! } ! ! public boolean equals(Object o) { ! if (o instanceof Variable) { ! return ((Variable)o).m_name.equals(m_name); ! } ! return false; ! } ! ! public int hashCode() { ! return m_name.hashCode(); ! } ! } ! --- 1,48 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.parser; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class Variable { ! ! private String m_name; ! public Variable(String name) { ! m_name = name; ! } ! public String getName() { return m_name; } ! ! public String toString() { ! return "$" + m_name; ! } ! ! public boolean equals(Object o) { ! if (o instanceof Variable) { ! return ((Variable)o).m_name.equals(m_name); ! } ! return false; ! } ! ! public int hashCode() { ! return m_name.hashCode(); ! } ! } ! Index: Projection.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/parser/Projection.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Projection.java 8 Mar 2005 12:33:40 -0000 1.2 --- Projection.java 8 Jul 2005 16:03:19 -0000 1.3 *************** *** 1,45 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.parser; ! ! import java.util.List; ! ! import org.tmapiutils.query.tolog.utils.VariableSet; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public interface Projection { ! public abstract void addVariable(Variable var); ! public abstract void addCount(Variable var); ! public abstract void addVariableSet(VariableSet varSet); ! /** ! * Returns the columns in the projection as a list of either Variable or Count ! * instances. ! * @return a list of column descriptors ! */ ! public abstract List getColumns(); ! /** ! * Returns the data rows in the projection. ! * @return a List of List instances, one per row in the projected data. ! */ ! public abstract List getRows(); ! } ! --- 1,45 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.parser; ! ! import java.util.List; ! ! import org.tmapiutils.query.tolog.utils.VariableSet; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public interface Projection { ! public abstract void addVariable(Variable var); ! public abstract void addCount(Variable var); ! public abstract void addVariableSet(VariableSet varSet); ! /** ! * Returns the columns in the projection as a list of either Variable or Count ! * instances. ! * @return a list of column descriptors ! */ ! public abstract List getColumns(); ! /** ! * Returns the data rows in the projection. ! * @return a List of List instances, one per row in the projected data. ! */ ! public abstract List getRows(); ! } ! Index: Sorting.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/parser/Sorting.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Sorting.java 8 Mar 2005 12:33:40 -0000 1.2 --- Sorting.java 8 Jul 2005 16:03:19 -0000 1.3 *************** *** 1,107 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.parser; ! ! import java.util.ArrayList; ! import java.util.Collections; ! import java.util.Comparator; ! import java.util.Iterator; ! import java.util.List; ! ! import org.tmapiutils.query.tolog.TologProcessingException; ! import org.tmapiutils.query.tolog.utils.DefaultRowComparator; ! import org.tmapiutils.query.tolog.utils.InvertedComparator; ! import org.tmapiutils.query.tolog.utils.RowComparator; ! ! /** ! * Represents the sorting part of a tolog query. This class keeps track ! * of the sort columns and the sort direction and provides a method for ! * sorting a projection. ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class Sorting { ! ! private List m_sortCols = new ArrayList(); ! private boolean m_sortAscending = true; ! private RowComparator m_rowComparator = null; ! private Comparator m_invRowComparator; ! ! public void addSort(Variable sortVar) { ! m_sortCols.add(sortVar); ! } ! ! public void setSortAscending(boolean sortAscending) { ! m_sortAscending = sortAscending; ! } ! ! /** ! * Sorts a list of results rows by this class's sorting criteria. The sort ! * is executed as an in-place sort of <code>rows</code>, so the ! * List returned by this method is in fact the same List object passed ! * in in the <code>rows</code> parameter. ! * @param columns the column headings for the list data to be sorted ! * @param rows the list data to be sorted ! * @return the list data sorted by the sorting criteria of this class. ! * @throws TologProcessingException if one of the sort columns set on ! * this Sorting instance cannot be found in the <code>columns</code> ! * list passed into the method. ! */ ! public List sort(List columns, List rows) throws TologProcessingException { ! if (m_sortCols.isEmpty()) return rows; ! if (m_rowComparator == null) { ! m_rowComparator = new DefaultRowComparator(); ! m_invRowComparator = new InvertedComparator(m_rowComparator); ! } ! Iterator c = m_sortCols.iterator(); ! while (c.hasNext()) { ! Object col = c.next(); ! int sortIx = columns.indexOf(col); ! if (sortIx == -1) { ! throw new TologProcessingException("Attempt to sort on non-existent column '" + col.toString() + "'"); ! } ! m_rowComparator.addSortColumn(sortIx); ! } ! Collections.sort(rows, m_sortAscending ? m_rowComparator : m_invRowComparator); ! return rows; ! } ! ! public String toString() { ! if (m_sortCols.isEmpty()) { ! return ""; ! } ! StringBuffer sb = new StringBuffer(); ! sb.append("order by "); ! Iterator it = m_sortCols.iterator(); ! while (it.hasNext()) { ! sb.append(it.next().toString()); ! if (it.hasNext()) { ! sb.append(","); ! } ! sb.append(" "); ! } ! if (m_sortAscending) { ! sb.append("asc"); ! } else { ! sb.append("desc"); ! } ! return sb.toString(); ! } ! } ! --- 1,107 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.parser; ! ! import java.util.ArrayList; ! import java.util.Collections; ! import java.util.Comparator; ! import java.util.Iterator; ! import java.util.List; ! ! import org.tmapiutils.query.tolog.TologProcessingException; ! import org.tmapiutils.query.tolog.utils.DefaultRowComparator; ! import org.tmapiutils.query.tolog.utils.InvertedComparator; ! import org.tmapiutils.query.tolog.utils.RowComparator; ! ! /** ! * Represents the sorting part of a tolog query. This class keeps track ! * of the sort columns and the sort direction and provides a method for ! * sorting a projection. ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class Sorting { ! ! private List m_sortCols = new ArrayList(); ! private boolean m_sortAscending = true; ! private RowComparator m_rowComparator = null; ! private Comparator m_invRowComparator; ! ! public void addSort(Variable sortVar) { ! m_sortCols.add(sortVar); ! } ! ! public void setSortAscending(boolean sortAscending) { ! m_sortAscending = sortAscending; ! } ! ! /** ! * Sorts a list of results rows by this class's sorting criteria. The sort ! * is executed as an in-place sort of <code>rows</code>, so the ! * List returned by this method is in fact the same List object passed ! * in in the <code>rows</code> parameter. ! * @param columns the column headings for the list data to be sorted ! * @param rows the list data to be sorted ! * @return the list data sorted by the sorting criteria of this class. ! * @throws TologProcessingException if one of the sort columns set on ! * this Sorting instance cannot be found in the <code>columns</code> ! * list passed into the method. ! */ ! public List sort(List columns, List rows) throws TologProcessingException { ! if (m_sortCols.isEmpty()) return rows; ! if (m_rowComparator == null) { ! m_rowComparator = new DefaultRowComparator(); ! m_invRowComparator = new InvertedComparator(m_rowComparator); ! } ! Iterator c = m_sortCols.iterator(); ! while (c.hasNext()) { ! Object col = c.next(); ! int sortIx = columns.indexOf(col); ! if (sortIx == -1) { ! throw new TologProcessingException("Attempt to sort on non-existent column '" + col.toString() + "'"); ! } ! m_rowComparator.addSortColumn(sortIx); ! } ! Collections.sort(rows, m_sortAscending ? m_rowComparator : m_invRowComparator); ! return rows; ! } ! ! public String toString() { ! if (m_sortCols.isEmpty()) { ! return ""; ! } ! StringBuffer sb = new StringBuffer(); ! sb.append("order by "); ! Iterator it = m_sortCols.iterator(); ! while (it.hasNext()) { ! sb.append(it.next().toString()); ! if (it.hasNext()) { ! sb.append(","); ! } ! sb.append(" "); ! } ! if (m_sortAscending) { ! sb.append("asc"); ! } else { ! sb.append("desc"); ! } ! return sb.toString(); ! } ! } ! Index: TologRuleInstance.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/parser/TologRuleInstance.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TologRuleInstance.java 8 Mar 2005 12:33:40 -0000 1.2 --- TologRuleInstance.java 8 Jul 2005 16:03:19 -0000 1.3 *************** *** 1,30 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.parser; ! ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public interface TologRuleInstance extends Predicate { ! ! ! } ! --- 1,30 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.parser; ! ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public interface TologRuleInstance extends Predicate { ! ! ! } ! Index: ProjectionImpl.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/parser/ProjectionImpl.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ProjectionImpl.java 8 Mar 2005 12:33:40 -0000 1.3 --- ProjectionImpl.java 8 Jul 2005 16:03:19 -0000 1.4 *************** *** 1,189 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.parser; ! ! import java.util.ArrayList; ! import java.util.Iterator; ! import java.util.List; ! ! import org.apache.commons.logging.Log; ! import org.apache.commons.logging.LogFactory; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! import org.tmapi.core.TopicMapObject; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class ProjectionImpl implements Projection { ! private List m_columns; ! private List m_rows; ! ! private static final Log m_log = LogFactory.getLog(ProjectionImpl.class); ! ! public ProjectionImpl () { ! m_columns = new ArrayList(); ! m_rows = new ArrayList(); ! } ! ! public void addVariable(Variable var) { ! m_columns.add(var); ! } ! ! public void addCount(Variable var) { ! m_columns.add(new Count(var)); ! } ! ! public void addVariableSet(VariableSet varSet) { ! if (m_columns.isEmpty()) { ! Iterator it = varSet.getColumns().iterator(); ! while (it.hasNext()) { ! m_columns.add((Variable)it.next()); ! } ! } ! int max = varSet.size(); ! for (int i = 0; i < max; i++) { ! List srcRow = varSet.getRow(i); ! List newRow = new ArrayList(); ! Iterator it = m_columns.iterator(); ! while (it.hasNext()) { ! Object c = it.next(); ! if (c instanceof Count) { ! int ix = varSet.indexOf(((Count)c).getVariable()); ! Object srcVal = srcRow.get(ix); ! if (((srcRow == null) || (srcRow.get(ix) instanceof Variable))) { ! newRow.add(new Integer(0)); ! } else { ! newRow.add(new Integer(1)); ! } ! } else { ! int ix = varSet.indexOf((Variable)c); ! Object srcVal = srcRow.get(ix); ! if ((srcRow == null) || (srcVal instanceof Variable)) { ! newRow.add(null); ! } else { ! newRow.add(srcVal); ! } ! } ! } ! ! if (m_log.isDebugEnabled()) debugRow("Adding new row: ", newRow); ! boolean hasMatch = false; ! it = m_rows.iterator(); ! while (!hasMatch && it.hasNext()) { ! List row = (List)it.next(); ! if (m_log.isDebugEnabled()) debugRow(" Compare to ", row); ! hasMatch = compareRows(newRow, row); ! if (hasMatch) { ! m_log.debug("New row matches existing row. Updating counts..."); ! // Just add the count parts to the matched row's counts ! for (int col = 0; col < row.size(); col++) { ! if (m_columns.get(col) instanceof Count) { ! int count = ((Integer)row.get(col)).intValue(); ! count += ((Integer)newRow.get(col)).intValue(); ! row.set(col, new Integer(count)); ! } ! } ! } ! } ! if (!hasMatch) { ! m_log.debug("Adding new row to projection."); ! m_rows.add(newRow); ! } ! } ! } ! ! private boolean compareRows(List r1, List r2) { ! for (int col = 0; col < r1.size(); col++) { ! if (m_columns.get(col) instanceof Count) continue; ! Object v1 = r1.get(col); ! Object v2 = r2.get(col); ! if ((v1 == null && v2 != null) || (v2 == null && v1 != null)) { ! return false; ! } else if (v1 == null && v2 == null) { ! return true; ! } else if (!(r1.get(col).equals(r2.get(col)))) { ! return false; ! } ! } ! return true; ! } ! ! /** ! * Returns the columns in the projection as a list of either Variable or Count ! * instances. ! * @return a list of column descriptors ! */ ! public List getColumns() { ! return m_columns; ! } ! ! /** ! * Returns the data rows in the projection. ! * @return a List of List instances, one per row in the projected data. ! */ ! public List getRows() { ! return m_rows; ! } ! ! public class Count { ! private Variable m_var; ! public Count(Variable var) { m_var = var; } ! public String getVarName() { return m_var.getName(); } ! public Variable getVariable() { return m_var; } ! public String toString() { ! return "count($" + m_var.getName() + ")"; ! } ! } ! ! private void debugRow(String msg, List row) { ! StringBuffer m = new StringBuffer(); ! m.append(msg); ! Iterator it = row.iterator(); ! while (it.hasNext()) { ! Object o = it.next(); ! if (o instanceof TopicMapObject) { ! m.append(((TopicMapObject)o).getObjectId()); ! } else { ! m.append(String.valueOf(o)); ! } ! if (it.hasNext()) { ! m.append(", "); ! } ! } ! m_log.debug(m.toString()); ! } ! ! public String toString() { ! if (m_columns.isEmpty()) { ! return "select * from"; ! } ! StringBuffer sb = new StringBuffer(); ! sb.append("select"); ! Iterator it = m_columns.iterator(); ! while(it.hasNext()) { ! sb.append(" "); ! sb.append(it.next().toString()); ! if (it.hasNext()) sb.append(","); ! } ! sb.append(" from"); ! return sb.toString(); ! } ! } ! --- 1,189 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.parser; ! ! import java.util.ArrayList; ! import java.util.Iterator; ! import java.util.List; ! ! import org.apache.commons.logging.Log; ! import org.apache.commons.logging.LogFactory; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! import org.tmapi.core.TopicMapObject; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class ProjectionImpl implements Projection { ! private List m_columns; ! private List m_rows; ! ! private static final Log m_log = LogFactory.getLog(ProjectionImpl.class); ! ! public ProjectionImpl () { ! m_columns = new ArrayList(); ! m_rows = new ArrayList(); ! } ! ! public void addVariable(Variable var) { ! m_columns.add(var); ! } ! ! public void addCount(Variable var) { ! m_columns.add(new Count(var)); ! } ! ! public void addVariableSet(VariableSet varSet) { ! if (m_columns.isEmpty()) { ! Iterator it = varSet.getColumns().iterator(); ! while (it.hasNext()) { ! m_columns.add((Variable)it.next()); ! } ! } ! int max = varSet.size(); ! for (int i = 0; i < max; i++) { ! List srcRow = varSet.getRow(i); ! List newRow = new ArrayList(); ! Iterator it = m_columns.iterator(); ! while (it.hasNext()) { ! Object c = it.next(); ! if (c instanceof Count) { ! int ix = varSet.indexOf(((Count)c).getVariable()); ! Object srcVal = srcRow.get(ix); ! if (((srcRow == null) || (srcRow.get(ix) instanceof Variable))) { ! newRow.add(new Integer(0)); ! } else { ! newRow.add(new Integer(1)); ! } ! } else { ! int ix = varSet.indexOf((Variable)c); ! Object srcVal = srcRow.get(ix); ! if ((srcRow == null) || (srcVal instanceof Variable)) { ! newRow.add(null); ! } else { ! newRow.add(srcVal); ! } ! } ! } ! ! if (m_log.isDebugEnabled()) debugRow("Adding new row: ", newRow); ! boolean hasMatch = false; ! it = m_rows.iterator(); ! while (!hasMatch && it.hasNext()) { ! List row = (List)it.next(); ! if (m_log.isDebugEnabled()) debugRow(" Compare to ", row); ! hasMatch = compareRows(newRow, row); ! if (hasMatch) { ! m_log.debug("New row matches existing row. Updating counts..."); ! // Just add the count parts to the matched row's counts ! for (int col = 0; col < row.size(); col++) { ! if (m_columns.get(col) instanceof Count) { ! int count = ((Integer)row.get(col)).intValue(); ! count += ((Integer)newRow.get(col)).intValue(); ! row.set(col, new Integer(count)); ! } ! } ! } ! } ! if (!hasMatch) { ! m_log.debug("Adding new row to projection."); ! m_rows.add(newRow); ! } ! } ! } ! ! private boolean compareRows(List r1, List r2) { ! for (int col = 0; col < r1.size(); col++) { ! if (m_columns.get(col) instanceof Count) continue; ! Object v1 = r1.get(col); ! Object v2 = r2.get(col); ! if ((v1 == null && v2 != null) || (v2 == null && v1 != null)) { ! return false; ! } else if (v1 == null && v2 == null) { ! return true; ! } else if (!(r1.get(col).equals(r2.get(col)))) { ! return false; ! } ! } ! return true; ! } ! ! /** ! * Returns the columns in the projection as a list of either Variable or Count ! * instances. ! * @return a list of column descriptors ! */ ! public List getColumns() { ! return m_columns; ! } ! ! /** ! * Returns the data rows in the projection. ! * @return a List of List instances, one per row in the projected data. ! */ ! public List getRows() { ! return m_rows; ! } ! ! public class Count { ! private Variable m_var; ! public Count(Variable var) { m_var = var; } ! public String getVarName() { return m_var.getName(); } ! public Variable getVariable() { return m_var; } ! public String toString() { ! return "count($" + m_var.getName() + ")"; ! } ! } ! ! private void debugRow(String msg, List row) { ! StringBuffer m = new StringBuffer(); ! m.append(msg); ! Iterator it = row.iterator(); ! while (it.hasNext()) { ! Object o = it.next(); ! if (o instanceof TopicMapObject) { ! m.append(((TopicMapObject)o).getObjectId()); ! } else { ! m.append(String.valueOf(o)); ! } ! if (it.hasNext()) { ! m.append(", "); ! } ! } ! m_log.debug(m.toString()); ! } ! ! public String toString() { ! if (m_columns.isEmpty()) { ! return "select * from"; ! } ! StringBuffer sb = new StringBuffer(); ! sb.append("select"); ! Iterator it = m_columns.iterator(); ! while(it.hasNext()) { ! sb.append(" "); ! sb.append(it.next().toString()); ! if (it.hasNext()) sb.append(","); ! } ! sb.append(" from"); ! return sb.toString(); ! } ! } ! Index: Clause.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/parser/Clause.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Clause.java 8 Mar 2005 12:33:40 -0000 1.2 --- Clause.java 8 Jul 2005 16:03:19 -0000 1.3 *************** *** 1,39 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.parser; ! ! import java.util.List; ! ! import org.tmapiutils.query.tolog.TologProcessingException; ! import org.tmapiutils.query.tolog.utils.TologContext; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public interface Clause { ! ! public void doReplacement(Object[] params) throws TologProcessingException; ! ! public VariableSet execute(VariableSet in, TologContext context) throws TologProcessingException; ! ! public List getVariables(); ! } ! --- 1,39 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.parser; ! ! import java.util.List; ! ! import org.tmapiutils.query.tolog.TologProcessingException; ! import org.tmapiutils.query.tolog.utils.TologContext; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public interface Clause { ! ! public void doReplacement(Object[] params) throws TologProcessingException; ! ! public VariableSet execute(VariableSet in, TologContext context) throws TologProcessingException; ! ! public List getVariables(); ! } ! Index: OrClause.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/parser/OrClause.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** OrClause.java 8 Mar 2005 12:33:40 -0000 1.2 --- OrClause.java 8 Jul 2005 16:03:19 -0000 1.3 *************** *** 1,97 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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.tmapiutils.query.tolog.parser; ! ! import java.util.ArrayList; ! import java.util.Iterator; ! import java.util.List; ! ! import org.apache.commons.logging.Log; ! import org.apache.commons.logging.LogFactory; ! import org.tmapiutils.query.tolog.TologProcessingException; ! import org.tmapiutils.query.tolog.utils.TologContext; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class OrClause implements Clause { ! ! private List m_children; ! private List m_vars; ! private static final Log m_log = LogFactory.getLog(OrClause.class); ! ! public OrClause() { ! m_children = new ArrayList(); ! m_vars = new ArrayList(); ! } ! ! public void add(Clause c) { ! m_children.add(c); ! Iterator it = c.getVariables().iterator(); ! while (it.hasNext()) { ! Variable v = (Variable)it.next(); ! if (!m_vars.contains(v)) { ! m_vars.add(v); ! } ! } ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.Clause#execute(org.tmapiutils.query.tolog.VariableSet) ! */ ! public VariableSet execute(VariableSet in, TologContext context) throws TologProcessingException { ! if (m_log.isDebugEnabled()) m_log.debug("Start OR " + toString()); ! VariableSet ret = new VariableSet(); ! Iterator it = m_children.iterator(); ! while (it.hasNext()) { ! ret.add(((Clause)it.next()).execute((VariableSet) in.clone(), context)); ! } ! if (m_log.isDebugEnabled()) m_log.debug("End OR " + toString()); ! return ret; ! } ! ! public String toString() { ! StringBuffer sb = new StringBuffer(); ! sb.append("{ "); ! Iterator it = m_children.iterator(); ! while (it.hasNext()) { ! sb.append(it.next().toString()); ! if (it.hasNext()) { ! sb.append(" | "); ! } ! } ! sb.append(" }"); ! return sb.toString(); ! } ! ! public List getVariables() { ! return m_vars; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.parser.Clause#doReplacement(java.lang.Object[]) ! */ ! public void doReplacement(Object[] params) throws TologProcessingException { ! for (Iterator it = m_children.iterator(); it.hasNext();) { ! ((Clause)it.next()).doReplacement(params); ! } ! } ! } --- 1,97 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. 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 s... [truncated message content] |