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: Lars H. <lh...@us...> - 2005-03-06 21:11:45
|
Update of /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/utils In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20057/src/org/tmapiutils/query/tolog/utils Modified Files: DefaultRowComparator.java ReferenceUtils.java VariableSet.java Log Message: More TM4J -> TMAPI translations Index: ReferenceUtils.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/utils/ReferenceUtils.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ReferenceUtils.java 6 Mar 2005 17:35:06 -0000 1.1 --- ReferenceUtils.java 6 Mar 2005 21:11:34 -0000 1.2 *************** *** 13,17 **** import java.util.Iterator; ! import org.tm4j.net.Locator; import org.tmapi.core.TopicMapObject; --- 13,17 ---- import java.util.Iterator; ! import org.tmapi.core.Locator; import org.tmapi.core.TopicMapObject; *************** *** 39,43 **** if (ret == null) { ! return "@" + tmo.getID(); } else { return ret; --- 39,43 ---- if (ret == null) { ! return "@" + tmo.getObjectId(); } else { return ret; *************** *** 48,51 **** --- 48,54 ---- /* * $Log$ + * Revision 1.2 2005/03/06 21:11:34 lheuer + * More TM4J -> TMAPI translations + * * Revision 1.1 2005/03/06 17:35:06 lheuer * Initial tolog import Index: DefaultRowComparator.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/utils/DefaultRowComparator.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** DefaultRowComparator.java 6 Mar 2005 17:35:06 -0000 1.1 --- DefaultRowComparator.java 6 Mar 2005 21:11:34 -0000 1.2 *************** *** 57,61 **** ret = ((TopicName)o1).getValue().compareTo(((TopicName)o2).getValue()); } else if (o1 instanceof TopicMapObject) { ! ret = ((TopicMapObject)o1).getID().compareTo(((TopicMapObject)o2).getID()); } } --- 57,61 ---- ret = ((TopicName)o1).getValue().compareTo(((TopicName)o2).getValue()); } else if (o1 instanceof TopicMapObject) { ! ret = ((TopicMapObject)o1).getObjectId().compareTo(((TopicMapObject)o2).getObjectId()); } } *************** *** 69,72 **** --- 69,75 ---- /* * $Log$ + * Revision 1.2 2005/03/06 21:11:34 lheuer + * More TM4J -> TMAPI translations + * * Revision 1.1 2005/03/06 17:35:06 lheuer * Initial tolog import Index: VariableSet.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/utils/VariableSet.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** VariableSet.java 6 Mar 2005 17:35:06 -0000 1.1 --- VariableSet.java 6 Mar 2005 21:11:34 -0000 1.2 *************** *** 172,176 **** Object o = it.next(); if (o instanceof TopicMapObject) { ! ret.append(((TopicMapObject)o).getID()); } else { ret.append(o.toString()); --- 172,176 ---- Object o = it.next(); if (o instanceof TopicMapObject) { ! ret.append(((TopicMapObject)o).getObjectId()); } else { ret.append(o.toString()); *************** *** 287,290 **** --- 287,293 ---- /* * $Log$ + * Revision 1.2 2005/03/06 21:11:34 lheuer + * More TM4J -> TMAPI translations + * * Revision 1.1 2005/03/06 17:35:06 lheuer * Initial tolog import |
From: Lars H. <lh...@us...> - 2005-03-06 21:11:45
|
Update of /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/test/backends In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20057/src/org/tmapiutils/query/tolog/test/backends Modified Files: QueryTestBase.java Log Message: More TM4J -> TMAPI translations Index: QueryTestBase.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/test/backends/QueryTestBase.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** QueryTestBase.java 6 Mar 2005 17:34:39 -0000 1.1 --- QueryTestBase.java 6 Mar 2005 21:11:34 -0000 1.2 *************** *** 16,20 **** import java.util.List; ! import org.tm4j.net.Locator; import org.tm4j.test.ConfigurableBackendTest; import org.tmapiutils.query.tolog.TologResultsSet; --- 16,20 ---- import java.util.List; ! import org.tmapi.core.Locator; import org.tm4j.test.ConfigurableBackendTest; import org.tmapiutils.query.tolog.TologResultsSet; *************** *** 99,103 **** Object o = (Object)it.next(); if (o instanceof Topic) { ! ret.append(((Topic)o).getID()); } else { ret.append(o.getClass().getName() + ": " + o.toString()); --- 99,103 ---- Object o = (Object)it.next(); if (o instanceof Topic) { ! ret.append(((Topic)o).getObjectId()); } else { ret.append(o.getClass().getName() + ": " + o.toString()); *************** *** 151,155 **** private boolean validate(TopicMapObject tmo, String expected) throws Exception { ! if (tmo.getID().equals(expected)) { return true; } else { --- 151,155 ---- private boolean validate(TopicMapObject tmo, String expected) throws Exception { ! if (tmo.getObjectId().equals(expected)) { return true; } else { *************** *** 166,169 **** --- 166,172 ---- /* * $Log$ + * Revision 1.2 2005/03/06 21:11:34 lheuer + * More TM4J -> TMAPI translations + * * Revision 1.1 2005/03/06 17:34:39 lheuer * Initial tolog import |
From: Lars H. <lh...@us...> - 2005-03-06 21:11:43
|
Update of /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20057/src/org/tmapiutils/query/tolog/predicates Modified Files: DirectInstanceOfPredicate.java DynamicAssociationPredicate.java TypePredicate.java Log Message: More TM4J -> TMAPI translations Index: TypePredicate.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/TypePredicate.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TypePredicate.java 6 Mar 2005 17:30:00 -0000 1.1 --- TypePredicate.java 6 Mar 2005 21:11:33 -0000 1.2 *************** *** 24,28 **** import org.tmapi.core.TopicMap; import org.tmapi.core.TopicMapObject; ! import org.tmapi.index.core.AssociationTypesIndex; import org.tmapi.index.core.AssociationRolesIndex; import org.tmapi.index.core.OccurrencesIndex; --- 24,28 ---- import org.tmapi.core.TopicMap; import org.tmapi.core.TopicMapObject; ! import org.tmapi.index.core.AssociationsIndex; import org.tmapi.index.core.AssociationRolesIndex; import org.tmapi.index.core.OccurrencesIndex; *************** *** 36,40 **** private AssociationRolesIndex m_mti; private OccurrencesIndex m_oti; ! private AssociationTypesIndex m_ati; public static final String PREDICATE_NAME = "type"; private static final ParameterInfo PARAM_INFO [] = new ParameterInfo[] { --- 36,40 ---- private AssociationRolesIndex m_mti; private OccurrencesIndex m_oti; ! private AssociationsIndex m_ati; public static final String PREDICATE_NAME = "type"; private static final ParameterInfo PARAM_INFO [] = new ParameterInfo[] { *************** *** 104,108 **** it = m_oti.getOccurrencesByType(type).iterator(); addInstances(type, it, ret); ! it = m_mti.getAssociationRolesOfType(type).iterator(); addInstances(type, it, ret); } --- 104,108 ---- it = m_oti.getOccurrencesByType(type).iterator(); addInstances(type, it, ret); ! it = m_mti.getAssociationRolesByType(type).iterator(); addInstances(type, it, ret); } *************** *** 156,160 **** for (Iterator types = m_mti.getAssociationRoleTypes().iterator(); types.hasNext();) { Topic type = (Topic)types.next(); ! for (Iterator instances = m_mti.getAssociationRolesOfType(type).iterator(); instances.hasNext();) { addResultsRow(ret, new Object[] { instances.next(), type }); } --- 156,160 ---- for (Iterator types = m_mti.getAssociationRoleTypes().iterator(); types.hasNext();) { Topic type = (Topic)types.next(); ! for (Iterator instances = m_mti.getAssociationRolesByType(type).iterator(); instances.hasNext();) { addResultsRow(ret, new Object[] { instances.next(), type }); } *************** *** 168,172 **** super.initialise(tm); try { ! m_ati = tm.getIndexManager().getAssociationTypesIndex(); if (!m_ati.isOpen()) m_ati.open(); m_oti = tm.getIndexManager().getOccurrencesIndex(); --- 168,172 ---- super.initialise(tm); try { ! m_ati = tm.getIndexManager().getAssociationsIndex(); if (!m_ati.isOpen()) m_ati.open(); m_oti = tm.getIndexManager().getOccurrencesIndex(); *************** *** 184,187 **** --- 184,190 ---- /* * $Log$ + * Revision 1.2 2005/03/06 21:11:33 lheuer + * More TM4J -> TMAPI translations + * * Revision 1.1 2005/03/06 17:30:00 lheuer * Initial tolog import Index: DynamicAssociationPredicate.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/DynamicAssociationPredicate.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** DynamicAssociationPredicate.java 6 Mar 2005 21:01:07 -0000 1.2 --- DynamicAssociationPredicate.java 6 Mar 2005 21:11:33 -0000 1.3 *************** *** 28,32 **** //import org.tmapi.core.index.IndexException; //import org.tmapi.core.index.IndexManagerException; ! //import org.tmapi.index.core.AssociationTypesIndex; //import org.tmapi.index.core.AssociationRolesIndex; //import org.tmapi.core.utils.extractors.AssociationExtractor; --- 28,32 ---- //import org.tmapi.core.index.IndexException; //import org.tmapi.core.index.IndexManagerException; ! //import org.tmapi.index.core.AssociationsIndex; //import org.tmapi.index.core.AssociationRolesIndex; //import org.tmapi.core.utils.extractors.AssociationExtractor; *************** *** 150,158 **** if (m_log.isDebugEnabled()) { if (role != null) { ! m_log.debug("matchOnRolePlayer( player:" + player.getID() + ", role:" + ! ((role instanceof Topic) ? ((Topic)role).getID() : "$" + ((Variable)role).getName()) + " )"); } else { ! m_log.debug("matchOnRolePlayer( player:" + player.getID() + ", role:<unspecified>"); } } --- 150,158 ---- if (m_log.isDebugEnabled()) { if (role != null) { ! m_log.debug("matchOnRolePlayer( player:" + player.getObjectId() + ", role:" + ! ((role instanceof Topic) ? ((Topic)role).getObjectId() : "$" + ((Variable)role).getName()) + " )"); } else { ! m_log.debug("matchOnRolePlayer( player:" + player.getObjectId() + ", role:<unspecified>"); } } *************** *** 348,352 **** if (playerRoleParam.getPlayerVar() != null) { if (m_log.isDebugEnabled()) { ! m_log.debug("Binding $" + playerRoleParam.getPlayerVar().getName() + " to topic " + prp.getPlayerTopic().getID()); } localBindings.put(playerRoleParam.getPlayerVar(), prp.getPlayerTopic()); --- 348,352 ---- if (playerRoleParam.getPlayerVar() != null) { if (m_log.isDebugEnabled()) { ! m_log.debug("Binding $" + playerRoleParam.getPlayerVar().getName() + " to topic " + prp.getPlayerTopic().getObjectId()); } localBindings.put(playerRoleParam.getPlayerVar(), prp.getPlayerTopic()); *************** *** 354,358 **** if (playerRoleParam.getRoleVar() != null) { if (m_log.isDebugEnabled()) { ! m_log.debug("Binding $" + playerRoleParam.getRoleVar().getName() + " to topic " + prp.getRoleTopic().getID()); } localBindings.put(playerRoleParam.getRoleVar(), prp.getRoleTopic()); --- 354,358 ---- if (playerRoleParam.getRoleVar() != null) { if (m_log.isDebugEnabled()) { ! m_log.debug("Binding $" + playerRoleParam.getRoleVar().getName() + " to topic " + prp.getRoleTopic().getObjectId()); } localBindings.put(playerRoleParam.getRoleVar(), prp.getRoleTopic()); *************** *** 388,392 **** Object param0 = it.next(); if (param0 instanceof Topic) { ! sb.append(((Topic)param0).getID()); } else { sb.append(param0.toString()); --- 388,392 ---- Object param0 = it.next(); if (param0 instanceof Topic) { ! sb.append(((Topic)param0).getObjectId()); } else { sb.append(param0.toString()); *************** *** 452,455 **** --- 452,458 ---- /* * $Log$ + * Revision 1.3 2005/03/06 21:11:33 lheuer + * More TM4J -> TMAPI translations + * * Revision 1.2 2005/03/06 21:01:07 lheuer * Removed getIndexManager() with getHelperObject(index.class) Index: DirectInstanceOfPredicate.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/DirectInstanceOfPredicate.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** DirectInstanceOfPredicate.java 6 Mar 2005 21:01:07 -0000 1.2 --- DirectInstanceOfPredicate.java 6 Mar 2005 21:11:33 -0000 1.3 *************** *** 147,151 **** */ private void checkInstance(Topic inst, Topic cls, VariableSet ret) throws TologProcessingException { ! m_log.debug("Check if " + inst.getID() + " is instance of " + cls.getID()); Iterator it = inst.getTypes().iterator(); while (it.hasNext()) { --- 147,151 ---- */ private void checkInstance(Topic inst, Topic cls, VariableSet ret) throws TologProcessingException { ! m_log.debug("Check if " + inst.getObjectId() + " is instance of " + cls.getObjectId()); Iterator it = inst.getTypes().iterator(); while (it.hasNext()) { *************** *** 213,216 **** --- 213,219 ---- /* * $Log$ + * Revision 1.3 2005/03/06 21:11:33 lheuer + * More TM4J -> TMAPI translations + * * Revision 1.2 2005/03/06 21:01:07 lheuer * Removed getIndexManager() with getHelperObject(index.class) |
From: Lars H. <lh...@us...> - 2005-03-06 21:01:18
|
Update of /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17744/src/org/tmapiutils/query/tolog/predicates Modified Files: DirectInstanceOfPredicate.java DynamicAssociationPredicate.java Log Message: Removed getIndexManager() with getHelperObject(index.class) Index: DirectInstanceOfPredicate.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/DirectInstanceOfPredicate.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** DirectInstanceOfPredicate.java 6 Mar 2005 17:29:58 -0000 1.1 --- DirectInstanceOfPredicate.java 6 Mar 2005 21:01:07 -0000 1.2 *************** *** 15,26 **** --- 15,33 ---- import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + 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.Topic; import org.tmapi.core.TopicMap; + import org.tmapi.core.TMAPIException; import org.tmapi.index.core.TopicsIndex; + /** * Implementation of the tolog built-in direct-instance-of *************** *** 68,74 **** super.initialise(tm); try { ! m_tti = tm.getIndexManager().getTopicsIndex(); ! if (!m_tti.isOpen()) m_tti.open(); ! } catch (Exception ex) { throw new TologParserException("Unable to initialise " + PREDICATE_NAME + " predicate.", ex); } --- 75,80 ---- super.initialise(tm); try { ! m_tti = (TopicsIndex) tm.getHelperObject(TopicsIndex.class); ! } catch (TMAPIException ex) { throw new TologParserException("Unable to initialise " + PREDICATE_NAME + " predicate.", ex); } *************** *** 165,168 **** --- 171,175 ---- */ private void getInstances(Topic cls, VariableSet ret) throws TologProcessingException { + IndexUtils.updateIndex(m_tti); Iterator it = m_tti.getTopicsByType(cls).iterator(); while (it.hasNext()) { *************** *** 192,195 **** --- 199,203 ---- */ private void openMatch(VariableSet ret) throws TologProcessingException { + IndexUtils.updateIndex(m_tti); Iterator types = m_tti.getTopicTypes().iterator(); while (types.hasNext()) { *************** *** 205,208 **** --- 213,219 ---- /* * $Log$ + * Revision 1.2 2005/03/06 21:01:07 lheuer + * Removed getIndexManager() with getHelperObject(index.class) + * * Revision 1.1 2005/03/06 17:29:58 lheuer * Initial tolog import Index: DynamicAssociationPredicate.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/DynamicAssociationPredicate.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** DynamicAssociationPredicate.java 6 Mar 2005 17:29:58 -0000 1.1 --- DynamicAssociationPredicate.java 6 Mar 2005 21:01:07 -0000 1.2 *************** *** 26,42 **** import org.tmapiutils.query.tolog.parser.Variable; import org.tmapiutils.query.tolog.utils.VariableSet; import org.tmapi.core.Association; import org.tmapi.core.AssociationRole; import org.tmapi.core.Topic; import org.tmapi.core.TopicMap; ! import org.tmapi.core.index.IndexException; ! import org.tmapi.core.index.IndexManagerException; ! import org.tmapi.index.core.AssociationTypesIndex; import org.tmapi.index.core.AssociationRolesIndex; - import org.tmapi.core.utils.extractors.AssociationExtractor; - import org.tmapi.core.utils.testers.TypeTester; - - import uk.co.jezuk.mango.iterators.PredicatedIterator; - import uk.co.jezuk.mango.iterators.TransformingIterator; /** --- 26,49 ---- import org.tmapiutils.query.tolog.parser.Variable; import org.tmapiutils.query.tolog.utils.VariableSet; + //import org.tmapi.core.index.IndexException; + //import org.tmapi.core.index.IndexManagerException; + //import org.tmapi.index.core.AssociationTypesIndex; + //import org.tmapi.index.core.AssociationRolesIndex; + //import org.tmapi.core.utils.extractors.AssociationExtractor; + //import org.tmapi.core.utils.testers.TypeTester; + + import uk.co.jezuk.mango.iterators.PredicatedIterator; + import uk.co.jezuk.mango.iterators.TransformingIterator; + + import org.tmapiutils.utils.IndexUtils; + + // TMAPI import org.tmapi.core.Association; import org.tmapi.core.AssociationRole; import org.tmapi.core.Topic; import org.tmapi.core.TopicMap; ! import org.tmapi.core.TMAPIException; ! import org.tmapi.index.core.AssociationsIndex; import org.tmapi.index.core.AssociationRolesIndex; /** *************** *** 48,53 **** private TopicMap m_tm; private Topic m_assocType = null; ! private AssociationTypesIndex m_ati; ! private AssociationRolesIndex m_mti; private static final Log m_log = LogFactory.getLog(DynamicAssociationPredicate.class); --- 55,60 ---- private TopicMap m_tm; private Topic m_assocType = null; ! private AssociationsIndex _assocIdx; ! private AssociationRolesIndex _roleIdx; private static final Log m_log = LogFactory.getLog(DynamicAssociationPredicate.class); *************** *** 57,69 **** m_tm = tm; try { ! m_ati = tm.getIndexManager().getAssociationTypesIndex(); ! if (!m_ati.isOpen()) m_ati.open(); ! m_mti = tm.getIndexManager().getAssociationRolesIndex(); ! if (!m_mti.isOpen()) m_mti.open(); } ! catch (IndexManagerException e) { ! throw new TologParserException("Unable to open indexes requred for AssociationPredicate", e); ! } catch (IndexException e) { ! throw new TologParserException("Unable to open indexes requred for AssociationPredicate", e); } } --- 64,72 ---- m_tm = tm; try { ! _assocIdx = (AssociationsIndex) tm.getHelperObject(AssociationsIndex.class); ! _roleIdx = (AssociationRolesIndex) tm.getHelperObject(AssociationRolesIndex.class); } ! catch (TMAPIException e) { ! throw new TologParserException("Unable to get indexes requred for AssociationPredicate", e); } } *************** *** 129,134 **** */ private VariableSet matchOnRoleType(Topic roleType, List params) throws TologProcessingException { ! Collection members = m_mti.getAssociationRolesOfType(roleType); ! return matchAssociations(new TransformingIterator(members.iterator(), new AssociationExtractor()), params); } --- 132,138 ---- */ private VariableSet matchOnRoleType(Topic roleType, List params) throws TologProcessingException { ! IndexUtils.updateIndex(_roleIdx); ! Collection roles = _roleIdx.getAssociationRolesByType(roleType); ! return matchAssociations(new TransformingIterator(roles.iterator(), new AssociationExtractor()), params); } *************** *** 138,142 **** */ private VariableSet matchOnAssocType(List params) throws TologProcessingException { ! Collection assocsToMatch = m_ati.getAssociationsByType((Topic)params.get(0)); return matchAssociations(assocsToMatch.iterator(), params); } --- 142,147 ---- */ private VariableSet matchOnAssocType(List params) throws TologProcessingException { ! IndexUtils.updateIndex(_assocIdx); ! Collection assocsToMatch = _assocIdx.getAssociationsByType((Topic)params.get(0)); return matchAssociations(assocsToMatch.iterator(), params); } *************** *** 362,371 **** Iterator it = assoc.getAssociationRoles().iterator(); while (it.hasNext()) { ! AssociationRole m = (AssociationRole)it.next(); ! Topic roleSpec = m.getType(); ! Iterator players = m.getPlayers().iterator(); ! while (players.hasNext()) { ! ret.add(new PlayerRolePair((Topic)players.next(), roleSpec)); ! } } return ret; --- 367,377 ---- Iterator it = assoc.getAssociationRoles().iterator(); while (it.hasNext()) { ! AssociationRole role = (AssociationRole)it.next(); ! Topic type = m.getType(); ! // Iterator players = m.getPlayers().iterator(); ! //while (players.hasNext()) { ! // ret.add(new PlayerRolePair((Topic)players.next(), roleSpec)); ! //} ! ret.add(new PlayerRolePair(role.getPlayer(), type)) } return ret; *************** *** 446,449 **** --- 452,458 ---- /* * $Log$ + * Revision 1.2 2005/03/06 21:01:07 lheuer + * Removed getIndexManager() with getHelperObject(index.class) + * * Revision 1.1 2005/03/06 17:29:58 lheuer * Initial tolog import |
From: Lars H. <lh...@us...> - 2005-03-06 21:01:18
|
Update of /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17744/src/org/tmapiutils/query/tolog Modified Files: todo-log.txt Log Message: Removed getIndexManager() with getHelperObject(index.class) Index: todo-log.txt =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/todo-log.txt,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** todo-log.txt 6 Mar 2005 18:26:37 -0000 1.1 --- todo-log.txt 6 Mar 2005 21:01:08 -0000 1.2 *************** *** 3,8 **** There are more ToDos, but this a beginning. :)) - - File: query\tolog\TologFragmentBuilderImpl.java line: 25 --- 3,6 ---- *************** *** 23,51 **** - File: query\tolog\predicates\AssociationRolePredicate.java - line: 62 - getParent() - Cannot resolve getParent - line: 77 - getParent() - Cannot resolve getParent - - - File: query\tolog\predicates\DirectInstanceOfPredicate.java - line: 70 - getIndexManager() - Should become getHelperObject(IndexInterface.class) - - File: query\tolog\predicates\DynamicAssociationPredicate.java - line: 59 - getIndexManager() - Should become getHelperObject(IndexInterface.class) - line: 61 - getIndexManager() - Should become getHelperObject(IndexInterface.class) - line: 366 - getPlayers() - AssociationRole can have only one player - File: query\tolog\predicates\InstanceOfPredicate.java line: 23 --- 21,24 ---- |
From: Lars H. <lh...@us...> - 2005-03-06 20:41:14
|
Update of /cvsroot/tmapi-utils/tmapi-utils/utils In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11732/utils Modified Files: terminology.py Log Message: Typo "getId" -> "getID" Index: terminology.py =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/utils/terminology.py,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** terminology.py 6 Mar 2005 19:36:28 -0000 1.6 --- terminology.py 6 Mar 2005 20:41:05 -0000 1.7 *************** *** 40,44 **** 'getAddress()':'getReference()', # TopicMapObject ! 'getId()':'getObjectId()', # ScopingTopic 'addTheme(':'.addScopingTopic(', --- 40,44 ---- 'getAddress()':'getReference()', # TopicMapObject ! 'getID()':'getObjectId()', # ScopingTopic 'addTheme(':'.addScopingTopic(', |
From: Lars H. <lh...@us...> - 2005-03-06 19:38:04
|
Update of /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27221/src/org/tmapiutils/query/tolog/predicates Modified Files: AssociationRolePredicate.java BaseLocatorPredicate.java ReifiesPredicate.java Log Message: Changed getTopicByID to getObjectById Index: AssociationRolePredicate.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/AssociationRolePredicate.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** AssociationRolePredicate.java 6 Mar 2005 17:29:58 -0000 1.1 --- AssociationRolePredicate.java 6 Mar 2005 19:37:22 -0000 1.2 *************** *** 60,64 **** matchRoles((Association)assoc, ret); } else if ((assoc instanceof Variable) && (role instanceof AssociationRole)) { ! addResultsRow(ret, new Object[] {((AssociationRole)role).getParent(), role}); } else if ((assoc instanceof Variable) && (role instanceof Variable)) { openMatch(ret); --- 60,64 ---- 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); *************** *** 74,80 **** * @param ret */ ! private void closedMatch(Association association, AssociationRole member, VariableSet ret) throws TologProcessingException { ! if (member.getParent().equals(association)) { ! addResultsRow(ret, new Object[] {association, member}); } } --- 74,80 ---- * @param ret */ ! private void closedMatch(Association association, AssociationRole role, VariableSet ret) throws TologProcessingException { ! if (role.getAssociation().equals(association)) { ! addResultsRow(ret, new Object[] {association, role}); } } *************** *** 109,112 **** --- 109,115 ---- /* * $Log$ + * Revision 1.2 2005/03/06 19:37:22 lheuer + * Changed getTopicByID to getObjectById + * * Revision 1.1 2005/03/06 17:29:58 lheuer * Initial tolog import Index: ReifiesPredicate.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/ReifiesPredicate.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ReifiesPredicate.java 6 Mar 2005 18:14:09 -0000 1.2 --- ReifiesPredicate.java 6 Mar 2005 19:37:23 -0000 1.3 *************** *** 138,143 **** /* * $Log$ * Revision 1.2 2005/03/06 18:14:09 lheuer ! * org.tm4j.net.Locator -> org.tmapi.core.Locator * * Revision 1.1 2005/03/06 17:30:00 lheuer --- 138,146 ---- /* * $Log$ + * Revision 1.3 2005/03/06 19:37:23 lheuer + * Changed getTopicByID to getObjectById + * * Revision 1.2 2005/03/06 18:14:09 lheuer ! * org.tmapi.core.Locator -> org.tmapi.core.Locator * * Revision 1.1 2005/03/06 17:30:00 lheuer Index: BaseLocatorPredicate.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/BaseLocatorPredicate.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** BaseLocatorPredicate.java 6 Mar 2005 18:14:09 -0000 1.2 --- BaseLocatorPredicate.java 6 Mar 2005 19:37:22 -0000 1.3 *************** *** 65,70 **** /* * $Log$ * Revision 1.2 2005/03/06 18:14:09 lheuer ! * org.tm4j.net.Locator -> org.tmapi.core.Locator * * Revision 1.1 2005/03/06 17:29:58 lheuer --- 65,73 ---- /* * $Log$ + * Revision 1.3 2005/03/06 19:37:22 lheuer + * Changed getTopicByID to getObjectById + * * Revision 1.2 2005/03/06 18:14:09 lheuer ! * org.tmapi.core.Locator -> org.tmapi.core.Locator * * Revision 1.1 2005/03/06 17:29:58 lheuer |
Update of /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27221/src/org/tmapiutils/query/tolog/predicates/test Modified Files: AssociationPredicateTest.java AssociationRolePredicateTest.java DirectInstanceOfPredicateTest.java DynamicAssociationPredicateTest.java InstanceOfPredicateTest.java OccurrencePredicateTest.java PredicateTestBase.java ResourcePredicateTest.java TopicMapPredicateTest.java TopicNameTest.java TypePredicateTest.java ValueLikePredicateTest.java ValuePredicateTest.java VariantPredicateTest.java Log Message: Changed getTopicByID to getObjectById Index: ResourcePredicateTest.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test/ResourcePredicateTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ResourcePredicateTest.java 6 Mar 2005 18:15:43 -0000 1.2 --- ResourcePredicateTest.java 6 Mar 2005 19:37:40 -0000 1.3 *************** *** 15,22 **** import java.util.List; - import org.tmapi.core.Locator; import org.tmapiutils.query.tolog.parser.Variable; import org.tmapiutils.query.tolog.predicates.ResourcePredicate; import org.tmapiutils.query.tolog.utils.VariableSet; import org.tmapi.core.Occurrence; --- 15,24 ---- 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.Topic; import org.tmapi.core.Occurrence; *************** *** 70,74 **** assertEquals(2, out.getColumns().size()); assertEquals(3, out.getRows().size()); ! Iterator it = m_tm.getTopicByID("techquila").getOccurrences().iterator(); while (it.hasNext()) { Occurrence o = (Occurrence)it.next(); --- 72,76 ---- assertEquals(2, out.getColumns().size()); assertEquals(3, out.getRows().size()); ! Iterator it = ((Topic) m_tm.getObjectById("techquila")).getOccurrences().iterator(); while (it.hasNext()) { Occurrence o = (Occurrence)it.next(); *************** *** 78,82 **** assertTrue(l.equals(o.getResource())); } ! it = m_tm.getTopicByID("tm4j").getOccurrences().iterator(); while (it.hasNext()) { Occurrence o = (Occurrence)it.next(); --- 80,84 ---- assertTrue(l.equals(o.getResource())); } ! it = ((Topic) m_tm.getObjectById("tm4j")).getOccurrences().iterator(); while (it.hasNext()) { Occurrence o = (Occurrence)it.next(); *************** *** 99,103 **** assertEquals(1, out.getColumns().size()); assertEquals(1, out.getRows().size()); ! Iterator it = m_tm.getTopicByID("techquila").getOccurrences().iterator(); while (it.hasNext()) { Occurrence o = (Occurrence)it.next(); --- 101,105 ---- assertEquals(1, out.getColumns().size()); assertEquals(1, out.getRows().size()); ! Iterator it = ((Topic) m_tm.getObjectById("techquila")).getOccurrences().iterator(); while (it.hasNext()) { Occurrence o = (Occurrence)it.next(); *************** *** 115,119 **** Locator l = m_tm.getLocatorFactory().createLocator("URI", "http://www.techquila.com/"); Occurrence o = null; ! Iterator it = m_tm.getTopicByID("techquila").getOccurrences().iterator(); while (it.hasNext()) { o = (Occurrence)it.next(); --- 117,121 ---- Locator l = m_tm.getLocatorFactory().createLocator("URI", "http://www.techquila.com/"); Occurrence o = null; ! Iterator it = ((Topic) m_tm.getObjectById("techquila")).getOccurrences().iterator(); while (it.hasNext()) { o = (Occurrence)it.next(); *************** *** 139,144 **** /* * $Log$ * Revision 1.2 2005/03/06 18:15:43 lheuer ! * org.tm4j.net.Locator -> org.tmapi.core.Locator * * Revision 1.1 2005/03/06 17:33:23 lheuer --- 141,149 ---- /* * $Log$ + * Revision 1.3 2005/03/06 19:37:40 lheuer + * Changed getTopicByID to getObjectById + * * Revision 1.2 2005/03/06 18:15:43 lheuer ! * org.tmapi.core.Locator -> org.tmapi.core.Locator * * Revision 1.1 2005/03/06 17:33:23 lheuer Index: PredicateTestBase.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test/PredicateTestBase.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PredicateTestBase.java 6 Mar 2005 18:15:43 -0000 1.2 --- PredicateTestBase.java 6 Mar 2005 19:37:40 -0000 1.3 *************** *** 63,68 **** /* * $Log$ * Revision 1.2 2005/03/06 18:15:43 lheuer ! * org.tm4j.net.Locator -> org.tmapi.core.Locator * * Revision 1.1 2005/03/06 17:33:23 lheuer --- 63,71 ---- /* * $Log$ + * Revision 1.3 2005/03/06 19:37:40 lheuer + * Changed getTopicByID to getObjectById + * * Revision 1.2 2005/03/06 18:15:43 lheuer ! * org.tmapi.core.Locator -> org.tmapi.core.Locator * * Revision 1.1 2005/03/06 17:33:23 lheuer Index: TopicMapPredicateTest.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test/TopicMapPredicateTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TopicMapPredicateTest.java 6 Mar 2005 17:33:23 -0000 1.1 --- TopicMapPredicateTest.java 6 Mar 2005 19:37:40 -0000 1.2 *************** *** 64,68 **** assertEquals(m_tm, out.getRow(0).get(0)); ! params.set(0, m_tm.getTopicByID("hello-world")); out = m_predicate.matches(params, m_context); assertNotNull(out); --- 64,68 ---- assertEquals(m_tm, out.getRow(0).get(0)); ! params.set(0, m_tm.getObjectById("hello-world")); out = m_predicate.matches(params, m_context); assertNotNull(out); *************** *** 74,77 **** --- 74,80 ---- /* * $Log$ + * Revision 1.2 2005/03/06 19:37:40 lheuer + * Changed getTopicByID to getObjectById + * * Revision 1.1 2005/03/06 17:33:23 lheuer * Initial tolog import Index: AssociationRolePredicateTest.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test/AssociationRolePredicateTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** AssociationRolePredicateTest.java 6 Mar 2005 17:33:23 -0000 1.1 --- AssociationRolePredicateTest.java 6 Mar 2005 19:37:23 -0000 1.2 *************** *** 55,59 **** ArrayList params = new ArrayList(); Variable a = new Variable("A"); ! AssociationRole m = (AssociationRole) m_tm.getTopicByID("fred").getRolesPlayed().iterator().next(); params.add(a); params.add(m); --- 55,59 ---- ArrayList params = new ArrayList(); Variable a = new Variable("A"); ! AssociationRole m = (AssociationRole) ((Topic) m_tm.getObjectById("fred")).getRolesPlayed().iterator().next(); params.add(a); params.add(m); *************** *** 68,72 **** public void testMatchRoles() throws Exception { ArrayList params = new ArrayList(); ! Association assoc = ((AssociationRole)m_tm.getTopicByID("barney").getRolesPlayed().iterator().next()).getParent(); Variable a = new Variable("A"); params.add(assoc); --- 68,72 ---- public void testMatchRoles() throws Exception { ArrayList params = new ArrayList(); ! Association assoc = ((AssociationRole) ((Topic) m_tm.getObjectById("barney")).getRolesPlayed().iterator().next()).getParent(); Variable a = new Variable("A"); params.add(assoc); *************** *** 106,110 **** params.add(b); m_predicate.setParameters(params); ! Topic fred = m_tm.getTopicByID("fred"); AssociationRole m = (AssociationRole) fred.getRolesPlayed().iterator().next(); Association assoc = m.getParent(); --- 106,110 ---- params.add(b); m_predicate.setParameters(params); ! Topic fred = (Topic) m_tm.getObjectById("fred"); AssociationRole m = (AssociationRole) fred.getRolesPlayed().iterator().next(); Association assoc = m.getParent(); *************** *** 116,120 **** assertEquals(1, out.getRows().size()); ! Topic barney = m_tm.getTopicByID("barney"); AssociationRole m2 = (AssociationRole)barney.getRolesPlayed().iterator().next(); params.set(1, m2); --- 116,120 ---- assertEquals(1, out.getRows().size()); ! Topic barney = (Topic) m_tm.getObjectById("barney"); AssociationRole m2 = (AssociationRole)barney.getRolesPlayed().iterator().next(); params.set(1, m2); *************** *** 127,130 **** --- 127,133 ---- /* * $Log$ + * Revision 1.2 2005/03/06 19:37:23 lheuer + * Changed getTopicByID to getObjectById + * * Revision 1.1 2005/03/06 17:33:23 lheuer * Initial tolog import Index: DirectInstanceOfPredicateTest.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test/DirectInstanceOfPredicateTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** DirectInstanceOfPredicateTest.java 6 Mar 2005 18:15:43 -0000 1.2 --- DirectInstanceOfPredicateTest.java 6 Mar 2005 19:37:23 -0000 1.3 *************** *** 73,77 **** Variable a = new Variable("A"); params.add(a); ! params.add(m_tm.getTopicByID("cake")); m_predicate.setParameters(params); VariableSet out = m_predicate.matches(params, m_context); --- 73,77 ---- 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); *************** *** 86,90 **** List params = new ArrayList(); Variable a = new Variable("A"); ! params.add(m_tm.getTopicByID("jaffacake")); params.add(a); m_predicate.setParameters(params); --- 86,90 ---- List params = new ArrayList(); Variable a = new Variable("A"); ! params.add(m_tm.getObjectById("jaffacake")); params.add(a); m_predicate.setParameters(params); *************** *** 101,107 **** Variable a = new Variable("A"); params.add(a); ! params.add(m_tm.getTopicByID("cake")); m_predicate.setParameters(params); ! params.set(0, m_tm.getTopicByID("jaffacake")); VariableSet out = m_predicate.matches(params, m_context); assertNotNull(out); --- 101,107 ---- Variable a = new Variable("A"); params.add(a); ! params.add(m_tm.getObjectById("cake")); m_predicate.setParameters(params); ! params.set(0, m_tm.getObjectById("jaffacake")); VariableSet out = m_predicate.matches(params, m_context); assertNotNull(out); Index: DynamicAssociationPredicateTest.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test/DynamicAssociationPredicateTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** DynamicAssociationPredicateTest.java 6 Mar 2005 18:15:43 -0000 1.2 --- DynamicAssociationPredicateTest.java 6 Mar 2005 19:37:23 -0000 1.3 *************** *** 61,67 **** DynamicAssociationPredicate p = new DynamicAssociationPredicate(); ArrayList params = new ArrayList(); ! params.add(m_tm.getTopicByID("worksfor")); ! params.add(new PlayerRoleVarPair(m_tm.getTopicByID("kal"), m_tm.getTopicByID("employee"))); ! params.add(new PlayerRoleVarPair(new Variable("A"), m_tm.getTopicByID("employer"))); p.setParameters(params); c.addPredicate(p); --- 61,67 ---- DynamicAssociationPredicate p = new DynamicAssociationPredicate(); ArrayList params = new ArrayList(); ! params.add(m_tm.getObjectById("worksfor")); ! params.add(new PlayerRoleVarPair((Topic) m_tm.getObjectById("kal"), (Topic) m_tm.getObjectById("employee"))); ! params.add(new PlayerRoleVarPair(new Variable("A"), (Topic) m_tm.getObjectById("employer"))); p.setParameters(params); c.addPredicate(p); *************** *** 73,77 **** assertNotNull(r); assertEquals(r.size(), 1); ! assertEquals(m_tm.getTopicByID("techquila"), r.get(0)); } --- 73,77 ---- assertNotNull(r); assertEquals(r.size(), 1); ! assertEquals(m_tm.getObjectById("techquila"), r.get(0)); } *************** *** 83,89 **** p.initialise(m_tm); ArrayList params = new ArrayList(); ! params.add(m_tm.getTopicByID("worksfor")); ! params.add(new PlayerRoleVarPair(new Variable("PERSON"), m_tm.getTopicByID("employee"))); ! params.add(new PlayerRoleVarPair(new Variable("COMPANY"), m_tm.getTopicByID("employer"))); p.setParameters(params); c.addPredicate(p); --- 83,89 ---- p.initialise(m_tm); ArrayList params = new ArrayList(); ! params.add(m_tm.getObjectById("worksfor")); ! params.add(new PlayerRoleVarPair(new Variable("PERSON"), (Topic) m_tm.getObjectById("employee"))); ! params.add(new PlayerRoleVarPair(new Variable("COMPANY"), (Topic) m_tm.getObjectById("employer"))); p.setParameters(params); c.addPredicate(p); *************** *** 98,106 **** assertEquals(row.size(), 2); assertTrue( ! row.get(0).equals(m_tm.getTopicByID("kal")) || ! row.get(0).equals(m_tm.getTopicByID("fred"))); assertTrue( ! row.get(1).equals(m_tm.getTopicByID("techquila")) || ! row.get(1).equals(m_tm.getTopicByID("bigcorp"))); } } --- 98,106 ---- assertEquals(row.size(), 2); assertTrue( ! row.get(0).equals(m_tm.getObjectById("kal")) || ! row.get(0).equals(m_tm.getObjectById("fred"))); assertTrue( ! row.get(1).equals(m_tm.getObjectById("techquila")) || ! row.get(1).equals(m_tm.getObjectById("bigcorp"))); } } *************** *** 112,117 **** ArrayList params = new ArrayList(); params.add(new Variable("ASSOC")); ! params.add(new PlayerRoleVarPair(new Variable("PERSON"), m_tm.getTopicByID("employee"))); ! params.add(new PlayerRoleVarPair(new Variable("COMPANY"), m_tm.getTopicByID("employer"))); p.setParameters(params); c.addPredicate(p); --- 112,117 ---- ArrayList params = new ArrayList(); params.add(new Variable("ASSOC")); ! params.add(new PlayerRoleVarPair(new Variable("PERSON"), (Topic) m_tm.getObjectById("employee"))); ! params.add(new PlayerRoleVarPair(new Variable("COMPANY"), (Topic) m_tm.getObjectById("employer"))); p.setParameters(params); c.addPredicate(p); *************** *** 126,136 **** assertNotNull(row); assertEquals(row.size(), 3); ! assertEquals(m_tm.getTopicByID("worksfor"), row.get(0)); assertTrue( ! row.get(1).equals(m_tm.getTopicByID("kal")) || ! row.get(1).equals(m_tm.getTopicByID("fred"))); assertTrue( ! row.get(2).equals(m_tm.getTopicByID("techquila")) || ! row.get(2).equals(m_tm.getTopicByID("bigcorp"))); } } --- 126,136 ---- assertNotNull(row); assertEquals(row.size(), 3); ! assertEquals(m_tm.getObjectById("worksfor"), row.get(0)); assertTrue( ! row.get(1).equals(m_tm.getObjectById("kal")) || ! row.get(1).equals(m_tm.getObjectById("fred"))); assertTrue( ! row.get(2).equals(m_tm.getObjectById("techquila")) || ! row.get(2).equals(m_tm.getObjectById("bigcorp"))); } } *************** *** 145,149 **** SerializedTopicMapSource src = new SerializedTopicMapSource(new StringReader(TESTMAP), loc, new LTMBuilder()); m_tm = m_provider.addTopicMap(src); ! assertNotNull(m_tm.getTopicByID("worksfor")); m_context = new TologContext(); } --- 145,149 ---- SerializedTopicMapSource src = new SerializedTopicMapSource(new StringReader(TESTMAP), loc, new LTMBuilder()); m_tm = m_provider.addTopicMap(src); ! assertNotNull(m_tm.getObjectById("worksfor")); m_context = new TologContext(); } *************** *** 155,160 **** /* * $Log$ * Revision 1.2 2005/03/06 18:15:43 lheuer ! * org.tm4j.net.Locator -> org.tmapi.core.Locator * * Revision 1.1 2005/03/06 17:33:23 lheuer --- 155,163 ---- /* * $Log$ + * Revision 1.3 2005/03/06 19:37:23 lheuer + * Changed getTopicByID to getObjectById + * * Revision 1.2 2005/03/06 18:15:43 lheuer ! * org.tmapi.core.Locator -> org.tmapi.core.Locator * * Revision 1.1 2005/03/06 17:33:23 lheuer Index: VariantPredicateTest.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test/VariantPredicateTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** VariantPredicateTest.java 6 Mar 2005 17:33:24 -0000 1.1 --- VariantPredicateTest.java 6 Mar 2005 19:37:40 -0000 1.2 *************** *** 54,58 **** m_predicate.setParameters(params); ! TopicName fredName = (TopicName) m_tm.getTopicByID("fred").getTopicNames().iterator().next(); params.set(0, fredName); VariableSet out = m_predicate.matches(params, m_context); --- 54,58 ---- m_predicate.setParameters(params); ! TopicName fredName = (TopicName) m_tm.getObjectById("fred").getTopicNames().iterator().next(); params.set(0, fredName); VariableSet out = m_predicate.matches(params, m_context); *************** *** 70,74 **** m_predicate.setParameters(params); ! TopicName fredName = (TopicName) m_tm.getTopicByID("fred").getTopicNames().iterator().next(); Variant fredVar = (Variant) fredName.getVariants().iterator().next(); params.set(1, fredVar); --- 70,74 ---- m_predicate.setParameters(params); ! TopicName fredName = (TopicName) m_tm.getObjectById("fred").getTopicNames().iterator().next(); Variant fredVar = (Variant) fredName.getVariants().iterator().next(); params.set(1, fredVar); *************** *** 87,91 **** m_predicate.setParameters(params); ! TopicName fredName = (TopicName) m_tm.getTopicByID("fred").getTopicNames().iterator().next(); Variant fredVar = (Variant) fredName.getVariants().iterator().next(); params.set(0, fredName); --- 87,91 ---- m_predicate.setParameters(params); ! TopicName fredName = (TopicName) m_tm.getObjectById("fred").getTopicNames().iterator().next(); Variant fredVar = (Variant) fredName.getVariants().iterator().next(); params.set(0, fredName); *************** *** 115,118 **** --- 115,121 ---- /* * $Log$ + * Revision 1.2 2005/03/06 19:37:40 lheuer + * Changed getTopicByID to getObjectById + * * Revision 1.1 2005/03/06 17:33:24 lheuer * Initial tolog import Index: ValuePredicateTest.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test/ValuePredicateTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ValuePredicateTest.java 6 Mar 2005 17:33:23 -0000 1.1 --- ValuePredicateTest.java 6 Mar 2005 19:37:40 -0000 1.2 *************** *** 18,23 **** import org.tmapiutils.query.tolog.predicates.ValuePredicate; import org.tmapiutils.query.tolog.utils.VariableSet; ! import org.tmapi.core.TopicName; import org.tmapi.core.DataObject; import org.tmapi.core.Occurrence; --- 18,28 ---- import org.tmapiutils.query.tolog.predicates.ValuePredicate; import org.tmapiutils.query.tolog.utils.VariableSet; ! ! // TODO: import org.tmapi.core.DataObject; + + // TMAPI + import org.tmapi.core.Topic; + import org.tmapi.core.TopicName; import org.tmapi.core.Occurrence; *************** *** 78,82 **** params.add(b); m_predicate.setParameters(params); ! TopicName bn = (TopicName)m_tm.getTopicByID("bond").getTopicNames().iterator().next(); params.set(0, bn); VariableSet out = m_predicate.matches(params, m_context); --- 83,87 ---- params.add(b); m_predicate.setParameters(params); ! TopicName bn = (TopicName) ((Topic) m_tm.getObjectById("bond")).getTopicNames().iterator().next(); params.set(0, bn); VariableSet out = m_predicate.matches(params, m_context); *************** *** 91,95 **** } ! Occurrence o = (Occurrence)m_tm.getTopicByID("bond").getOccurrences().iterator().next(); assertNotNull(o.getValue()); params.set(0, o); --- 96,100 ---- } ! Occurrence o = (Occurrence) ((Topic) m_tm.getObjectById("bond")).getOccurrences().iterator().next(); assertNotNull(o.getValue()); params.set(0, o); *************** *** 108,112 **** params.add(b); m_predicate.setParameters(params); ! TopicName bn = (TopicName)m_tm.getTopicByID("bond").getTopicNames().iterator().next(); params.set(0, bn); params.set(1, bn.getValue()); --- 113,117 ---- params.add(b); m_predicate.setParameters(params); ! TopicName bn = (TopicName) ((Topic) m_tm.getObjectById("bond")).getTopicNames().iterator().next(); params.set(0, bn); params.set(1, bn.getValue()); *************** *** 128,132 **** assertEquals(0, out.getRows().size()); ! Occurrence o = (Occurrence)m_tm.getTopicByID("bond").getOccurrences().iterator().next(); assertNotNull(o.getValue()); params.set(0, o); --- 133,137 ---- assertEquals(0, out.getRows().size()); ! Occurrence o = (Occurrence) ((Topic) m_tm.getObjectById("bond")).getOccurrences().iterator().next(); assertNotNull(o.getValue()); params.set(0, o); *************** *** 174,177 **** --- 179,185 ---- /* * $Log$ + * Revision 1.2 2005/03/06 19:37:40 lheuer + * Changed getTopicByID to getObjectById + * * Revision 1.1 2005/03/06 17:33:23 lheuer * Initial tolog import Index: TopicNameTest.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test/TopicNameTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TopicNameTest.java 6 Mar 2005 17:33:23 -0000 1.1 --- TopicNameTest.java 6 Mar 2005 19:37:40 -0000 1.2 *************** *** 43,47 **** public void testMatchOnName() throws Exception { ! Topic topic1 = m_tm.getTopicByID("topic1"); TopicName bn = (TopicName) topic1.getTopicNames().iterator().next(); --- 43,47 ---- public void testMatchOnName() throws Exception { ! Topic topic1 = (Topic) m_tm.getObjectById("topic1"); TopicName bn = (TopicName) topic1.getTopicNames().iterator().next(); *************** *** 61,65 **** public void testMatchOnTopic() throws Exception { ! Topic topic3 = m_tm.getTopicByID("topic3"); ArrayList params = new ArrayList(); Variable a = new Variable("A"); --- 61,65 ---- public void testMatchOnTopic() throws Exception { ! Topic topic3 = (Topic) m_tm.getObjectById("topic3"); ArrayList params = new ArrayList(); Variable a = new Variable("A"); *************** *** 91,101 **** assertNotNull(out); assertEquals(4, out.getRows().size()); ! assertFalse(out.getColumn(a).contains(m_tm.getTopicByID("topic4"))); } public void testClosedMatch() throws Exception { ! Topic topic1 = m_tm.getTopicByID("topic1"); TopicName bn1 = (TopicName) topic1.getTopicNames().iterator().next(); ! Topic topic2 = m_tm.getTopicByID("topic2"); ArrayList params = new ArrayList(); --- 91,101 ---- assertNotNull(out); assertEquals(4, out.getRows().size()); ! assertFalse(out.getColumn(a).contains(m_tm.getObjectById("topic4"))); } public void testClosedMatch() throws Exception { ! Topic topic1 = (Topic) m_tm.getObjectById("topic1"); TopicName bn1 = (TopicName) topic1.getTopicNames().iterator().next(); ! Topic topic2 = (Topic) m_tm.getObjectById("topic2"); ArrayList params = new ArrayList(); Index: TypePredicateTest.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test/TypePredicateTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TypePredicateTest.java 6 Mar 2005 17:33:23 -0000 1.1 --- TypePredicateTest.java 6 Mar 2005 19:37:40 -0000 1.2 *************** *** 58,62 **** m_predicate.setParameters(params); ! Topic fred = m_tm.getTopicByID("fred"); params.set(0, fred.getOccurrences().iterator().next()); --- 58,62 ---- m_predicate.setParameters(params); ! Topic fred = (Topic) m_tm.getObjectById("fred"); params.set(0, fred.getOccurrences().iterator().next()); *************** *** 64,68 **** assertNotNull(out); assertEquals(1, out.getRows().size()); ! assertEquals(m_tm.getTopicByID("bootsize"), out.getRow(0).get(1)); AssociationRole fredRole = (AssociationRole) fred.getRolesPlayed().iterator().next(); --- 64,68 ---- assertNotNull(out); assertEquals(1, out.getRows().size()); ! assertEquals(m_tm.getObjectById("bootsize"), out.getRow(0).get(1)); AssociationRole fredRole = (AssociationRole) fred.getRolesPlayed().iterator().next(); *************** *** 71,75 **** assertNotNull(out); assertEquals(1, out.getRows().size()); ! assertEquals(m_tm.getTopicByID("employee"), out.getRow(0).get(1)); params.set(0, fredRole.getParent()); --- 71,75 ---- assertNotNull(out); assertEquals(1, out.getRows().size()); ! assertEquals(m_tm.getObjectById("employee"), out.getRow(0).get(1)); params.set(0, fredRole.getParent()); *************** *** 77,81 **** assertNotNull(out); assertEquals(1, out.getRows().size()); ! assertEquals(m_tm.getTopicByID("works-for"), out.getRow(0).get(1)); } --- 77,81 ---- assertNotNull(out); assertEquals(1, out.getRows().size()); ! assertEquals(m_tm.getObjectById("works-for"), out.getRow(0).get(1)); } *************** *** 88,92 **** m_predicate.setParameters(params); ! params.set(1, m_tm.getTopicByID("bootsize")); VariableSet out = m_predicate.matches(params, m_context); assertNotNull(out); --- 88,92 ---- m_predicate.setParameters(params); ! params.set(1, m_tm.getObjectById("bootsize")); VariableSet out = m_predicate.matches(params, m_context); assertNotNull(out); *************** *** 94,98 **** assertTrue(out.getRow(0).get(0) instanceof Occurrence); ! params.set(1, m_tm.getTopicByID("employee")); out = m_predicate.matches(params, m_context); assertNotNull(out); --- 94,98 ---- assertTrue(out.getRow(0).get(0) instanceof Occurrence); ! params.set(1, m_tm.getObjectById("employee")); out = m_predicate.matches(params, m_context); assertNotNull(out); *************** *** 100,104 **** assertTrue(out.getRow(0).get(0) instanceof AssociationRole); ! params.set(1, m_tm.getTopicByID("works-for")); out = m_predicate.matches(params, m_context); assertNotNull(out); --- 100,104 ---- assertTrue(out.getRow(0).get(0) instanceof AssociationRole); ! params.set(1, m_tm.getObjectById("works-for")); out = m_predicate.matches(params, m_context); assertNotNull(out); *************** *** 115,121 **** m_predicate.setParameters(params); ! Topic fred = m_tm.getTopicByID("fred"); params.set(0, fred.getOccurrences().iterator().next()); ! params.set(1, m_tm.getTopicByID("bootsize")); VariableSet out = m_predicate.matches(params, m_context); assertNotNull(out); --- 115,121 ---- m_predicate.setParameters(params); ! Topic fred = (Topic) m_tm.getObjectById("fred"); params.set(0, fred.getOccurrences().iterator().next()); ! params.set(1, m_tm.getObjectById("bootsize")); VariableSet out = m_predicate.matches(params, m_context); assertNotNull(out); *************** *** 124,128 **** AssociationRole fredRole = (AssociationRole) fred.getRolesPlayed().iterator().next(); params.set(0, fredRole); ! params.set(1, m_tm.getTopicByID("employee")); out = m_predicate.matches(params, m_context); assertNotNull(out); --- 124,128 ---- AssociationRole fredRole = (AssociationRole) fred.getRolesPlayed().iterator().next(); params.set(0, fredRole); ! params.set(1, m_tm.getObjectById("employee")); out = m_predicate.matches(params, m_context); assertNotNull(out); *************** *** 130,134 **** params.set(0, fredRole.getParent()); ! params.set(1, m_tm.getTopicByID("works-for")); out = m_predicate.matches(params, m_context); assertNotNull(out); --- 130,134 ---- params.set(0, fredRole.getParent()); ! params.set(1, m_tm.getObjectById("works-for")); out = m_predicate.matches(params, m_context); assertNotNull(out); *************** *** 164,167 **** --- 164,170 ---- /* * $Log$ + * Revision 1.2 2005/03/06 19:37:40 lheuer + * Changed getTopicByID to getObjectById + * * Revision 1.1 2005/03/06 17:33:23 lheuer * Initial tolog import Index: AssociationPredicateTest.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test/AssociationPredicateTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** AssociationPredicateTest.java 6 Mar 2005 17:33:23 -0000 1.1 --- AssociationPredicateTest.java 6 Mar 2005 19:37:23 -0000 1.2 *************** *** 76,80 **** assertEquals(1, out.getRows().size()); ! params.set(0, m_tm.getTopicByID("fred")); out = m_predicate.matches(params, m_context); assertNotNull(out); --- 76,80 ---- assertEquals(1, out.getRows().size()); ! params.set(0, m_tm.getObjectById("fred")); out = m_predicate.matches(params, m_context); assertNotNull(out); *************** *** 86,89 **** --- 86,92 ---- /* * $Log$ + * Revision 1.2 2005/03/06 19:37:23 lheuer + * Changed getTopicByID to getObjectById + * * Revision 1.1 2005/03/06 17:33:23 lheuer * Initial tolog import Index: OccurrencePredicateTest.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test/OccurrencePredicateTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** OccurrencePredicateTest.java 6 Mar 2005 17:33:23 -0000 1.1 --- OccurrencePredicateTest.java 6 Mar 2005 19:37:23 -0000 1.2 *************** *** 17,20 **** --- 17,22 ---- import org.tmapiutils.query.tolog.predicates.OccurrencePredicate; import org.tmapiutils.query.tolog.utils.VariableSet; + // TMAPI + import org.tmapi.core.Topic; /** *************** *** 72,80 **** assertTrue(out.getColumn(a).contains(m_tm.getObjectByID("techquila"))); assertTrue(out.getColumn(a).contains(m_tm.getObjectByID("tm4j"))); ! Iterator it = m_tm.getTopicByID("techquila").getOccurrences().iterator(); while (it.hasNext()) { assertTrue(out.getColumn(b).contains(it.next())); } ! it = m_tm.getTopicByID("tm4j").getOccurrences().iterator(); while (it.hasNext()) { assertTrue(out.getColumn(b).contains(it.next())); --- 74,82 ---- assertTrue(out.getColumn(a).contains(m_tm.getObjectByID("techquila"))); assertTrue(out.getColumn(a).contains(m_tm.getObjectByID("tm4j"))); ! Iterator it = ((Topic) m_tm.getObjectById("techquila")).getOccurrences().iterator(); while (it.hasNext()) { assertTrue(out.getColumn(b).contains(it.next())); } ! it = ((Topic) m_tm.getObjectById("tm4j")).getOccurrences().iterator(); while (it.hasNext()) { assertTrue(out.getColumn(b).contains(it.next())); *************** *** 86,90 **** Variable a = new Variable("A"); params.add(a); ! params.add(m_tm.getTopicByID("techquila").getOccurrences().iterator().next()); m_predicate.setParameters(params); VariableSet out = m_predicate.matches(params, m_context); --- 88,92 ---- Variable a = new Variable("A"); params.add(a); ! params.add(m_tm.getObjectById("techquila").getOccurrences().iterator().next()); m_predicate.setParameters(params); VariableSet out = m_predicate.matches(params, m_context); *************** *** 92,96 **** assertEquals(1, out.getColumns().size()); assertEquals(1, out.getRows().size()); ! assertTrue(out.getRow(0).contains(m_tm.getTopicByID("techquila"))); } --- 94,98 ---- assertEquals(1, out.getColumns().size()); assertEquals(1, out.getRows().size()); ! assertTrue(out.getRow(0).contains(m_tm.getObjectById("techquila"))); } *************** *** 98,102 **** List params = new ArrayList(); Variable a = new Variable("A"); ! params.add(m_tm.getTopicByID("techquila")); params.add(a); m_predicate.setParameters(params); --- 100,104 ---- List params = new ArrayList(); Variable a = new Variable("A"); ! params.add(m_tm.getObjectById("techquila")); params.add(a); m_predicate.setParameters(params); *************** *** 105,109 **** assertEquals(1, out.getColumns().size()); assertEquals(2, out.getRows().size()); ! Iterator it = m_tm.getTopicByID("techquila").getOccurrences().iterator(); while (it.hasNext()) { assertTrue(out.getColumn(a).contains(it.next())); --- 107,111 ---- assertEquals(1, out.getColumns().size()); assertEquals(2, out.getRows().size()); ! Iterator it = ((Topic) m_tm.getObjectById("techquila")).getOccurrences().iterator(); while (it.hasNext()) { assertTrue(out.getColumn(a).contains(it.next())); *************** *** 118,127 **** params.add(b); m_predicate.setParameters(params); ! params.set(0, m_tm.getTopicByID("tm4j")); ! params.set(1, m_tm.getTopicByID("tm4j").getOccurrences().iterator().next()); VariableSet out = m_predicate.matches(params, m_context); assertNotNull(out); assertEquals(1, out.getRows().size()); ! params.set(0, m_tm.getTopicByID("techquila")); out = m_predicate.matches(params, m_context); assertNotNull(out); --- 120,129 ---- params.add(b); m_predicate.setParameters(params); ! params.set(0, m_tm.getObjectById("tm4j")); ! params.set(1, m_tm.getObjectById("tm4j").getOccurrences().iterator().next()); VariableSet out = m_predicate.matches(params, m_context); assertNotNull(out); assertEquals(1, out.getRows().size()); ! params.set(0, m_tm.getObjectById("techquila")); out = m_predicate.matches(params, m_context); assertNotNull(out); *************** *** 132,135 **** --- 134,140 ---- /* * $Log$ + * Revision 1.2 2005/03/06 19:37:23 lheuer + * Changed getTopicByID to getObjectById + * * Revision 1.1 2005/03/06 17:33:23 lheuer * Initial tolog import Index: InstanceOfPredicateTest.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test/InstanceOfPredicateTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** InstanceOfPredicateTest.java 6 Mar 2005 17:33:23 -0000 1.1 --- InstanceOfPredicateTest.java 6 Mar 2005 19:37:23 -0000 1.2 *************** *** 103,107 **** params.add(b); m_predicate.setParameters(params); ! params.set(0, m_tm.getTopicByID("nelly")); params.set(1, m_tm.getObjectByID("mammal")); VariableSet out = m_predicate.matches(params, m_context); --- 103,107 ---- params.add(b); m_predicate.setParameters(params); ! params.set(0, m_tm.getObjectById("nelly")); params.set(1, m_tm.getObjectByID("mammal")); VariableSet out = m_predicate.matches(params, m_context); *************** *** 109,113 **** assertEquals(1, out.getRows().size()); ! params.set(0, m_tm.getTopicByID("nelly")); params.set(1, m_tm.getObjectByID("reptile")); out = m_predicate.matches(params, m_context); --- 109,113 ---- assertEquals(1, out.getRows().size()); ! params.set(0, m_tm.getObjectById("nelly")); params.set(1, m_tm.getObjectByID("reptile")); out = m_predicate.matches(params, m_context); *************** *** 120,123 **** --- 120,126 ---- /* * $Log$ + * Revision 1.2 2005/03/06 19:37:23 lheuer + * Changed getTopicByID to getObjectById + * * Revision 1.1 2005/03/06 17:33:23 lheuer * Initial tolog import Index: ValueLikePredicateTest.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test/ValueLikePredicateTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ValueLikePredicateTest.java 6 Mar 2005 18:15:43 -0000 1.2 --- ValueLikePredicateTest.java 6 Mar 2005 19:37:40 -0000 1.3 *************** *** 15,26 **** import java.util.Iterator; - import org.tmapi.core.Locator; import org.tmapiutils.query.tolog.parser.Predicate; import org.tmapiutils.query.tolog.parser.Variable; import org.tmapiutils.query.tolog.predicates.ValueLikePredicate; import org.tmapiutils.query.tolog.utils.VariableSet; ! import org.tmapi.core.TopicName; ! import org.tmapi.core.Occurrence; ! import org.tmapi.core.TopicMapObject; import org.tmapi.core.TopicMapProviderFactory; import org.tmapi.core.memory.TopicMapProviderFactoryImpl; --- 15,24 ---- import java.util.Iterator; import org.tmapiutils.query.tolog.parser.Predicate; import org.tmapiutils.query.tolog.parser.Variable; import org.tmapiutils.query.tolog.predicates.ValueLikePredicate; import org.tmapiutils.query.tolog.utils.VariableSet; ! ! // xxxx TODO xxxx import org.tmapi.core.TopicMapProviderFactory; import org.tmapi.core.memory.TopicMapProviderFactoryImpl; *************** *** 28,31 **** --- 26,36 ---- import org.tmapi.core.source.SerializedTopicMapSource; + // TMAPI + import org.tmapi.core.Locator; + import org.tmapi.core.Topic; + import org.tmapi.core.TopicName; + import org.tmapi.core.Occurrence; + import org.tmapi.core.TopicMapObject; + /** * *************** *** 82,86 **** m_predicate.setParameters(params); ! Iterator it = (m_tm.getTopicByID("test").getOccurrences().iterator()); while (it.hasNext()) { Occurrence o = (Occurrence)it.next(); --- 87,91 ---- m_predicate.setParameters(params); ! Iterator it = ((Topic) m_tm.getObjectById("test")).getOccurrences().iterator(); while (it.hasNext()) { Occurrence o = (Occurrence)it.next(); *************** *** 121,126 **** /* * $Log$ * Revision 1.2 2005/03/06 18:15:43 lheuer ! * org.tm4j.net.Locator -> org.tmapi.core.Locator * * Revision 1.1 2005/03/06 17:33:23 lheuer --- 126,134 ---- /* * $Log$ + * Revision 1.3 2005/03/06 19:37:40 lheuer + * Changed getTopicByID to getObjectById + * * Revision 1.2 2005/03/06 18:15:43 lheuer ! * org.tmapi.core.Locator -> org.tmapi.core.Locator * * Revision 1.1 2005/03/06 17:33:23 lheuer |
From: Lars H. <lh...@us...> - 2005-03-06 19:36:38
|
Update of /cvsroot/tmapi-utils/tmapi-utils/utils In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27021/utils Modified Files: terminology.py Log Message: More critical words Index: terminology.py =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/utils/terminology.py,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** terminology.py 6 Mar 2005 19:11:26 -0000 1.5 --- terminology.py 6 Mar 2005 19:36:28 -0000 1.6 *************** *** 100,103 **** --- 100,106 ---- 'IDGeneratorFactory':'Has become org.tmapi.core.utils.IDGeneratorFactory', 'LocatorFactory':'Has become org.tmapi.core.LocatorFactory<Exception>. Has no TMAPI equivalent', + 'LTMBuilder':'Has become core.utils.LTMBuilder. No equivalent in TMAPI / TMAPIUtils', + 'Lucene':'Fulltext index not available', + 'SerializedTopicMap':'No equivalent', # Topic 'getSubject()':'Replaced just getSubject() -> getSubjectLocators(). ToDo: .iterator().next() or something', |
From: Lars H. <lh...@us...> - 2005-03-06 19:11:37
|
Update of /cvsroot/tmapi-utils/tmapi-utils/utils In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19254/utils Modified Files: terminology.py Log Message: Typo TopicById -> TopicByID Index: terminology.py =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/utils/terminology.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** terminology.py 6 Mar 2005 18:08:26 -0000 1.4 --- terminology.py 6 Mar 2005 19:11:26 -0000 1.5 *************** *** 47,51 **** 'getTopicsIterator()':'getTopics().iterator()', 'getAssociationsIterator()':'getAssociations().iterator()', ! 'getTopicById(':'getObjectById(', # Topic 'getNames()':'getTopicNames()', --- 47,51 ---- 'getTopicsIterator()':'getTopics().iterator()', 'getAssociationsIterator()':'getAssociations().iterator()', ! 'getTopicByID(':'getObjectById(', # Topic 'getNames()':'getTopicNames()', *************** *** 108,112 **** 'getTopicBySubjectIndicator(':'TopicMap.getTopicBySubjectIndicator -> TopicsIndex.getTopicBySubjectIdentifier', 'getObjectBySourceLocator(':'TopicMap.getObjectBySourceLocator -> TopicMapObjectsIndex.getTopicMapObjectBySourceLocator', ! 'getTopicById':'Has become "getObjectById". Typecast necessary!', # ScopedObjectsIndex 'getScopedObjects(':'Could be getScopedObjectsByScopingTopic or ..ByScopingTopics', --- 108,112 ---- 'getTopicBySubjectIndicator(':'TopicMap.getTopicBySubjectIndicator -> TopicsIndex.getTopicBySubjectIdentifier', 'getObjectBySourceLocator(':'TopicMap.getObjectBySourceLocator -> TopicMapObjectsIndex.getTopicMapObjectBySourceLocator', ! 'getTopicByID':'Has become "getObjectById". Typecast necessary!', # ScopedObjectsIndex 'getScopedObjects(':'Could be getScopedObjectsByScopingTopic or ..ByScopingTopics', |
From: Lars H. <lh...@us...> - 2005-03-06 18:26:47
|
Update of /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8579/src/org/tmapiutils/query/tolog Added Files: todo-log.txt Log Message: Log generated by the tm4j2tmapi script. --- NEW FILE: todo-log.txt --- This log file was generated by the tm4j2tmapi.py script. There are more ToDos, but this a beginning. :)) File: query\tolog\TologFragmentBuilderImpl.java line: 25 IDGeneratorFactory Has become org.tmapi.core.utils.IDGeneratorFactory line: 47 IDGeneratorFactory Has become org.tmapi.core.utils.IDGeneratorFactory line: 119 createName Must become "createTopicName" line: 154 createName Must become "createTopicName" line: 210 createMember Must become "createAssociationRole" File: query\tolog\predicates\AssociationRolePredicate.java line: 62 getParent() Cannot resolve getParent line: 77 getParent() Cannot resolve getParent File: query\tolog\predicates\DirectInstanceOfPredicate.java line: 70 getIndexManager() Should become getHelperObject(IndexInterface.class) File: query\tolog\predicates\DynamicAssociationPredicate.java line: 59 getIndexManager() Should become getHelperObject(IndexInterface.class) line: 61 getIndexManager() Should become getHelperObject(IndexInterface.class) line: 366 getPlayers() AssociationRole can have only one player File: query\tolog\predicates\InstanceOfPredicate.java line: 23 TopicMapUtils Usage of org.tm4j.topicmap.TopicMapUtils (has become org.tmapi.core.TopicMapUtils!) line: 35 TopicMapUtils Usage of org.tm4j.topicmap.TopicMapUtils (has become org.tmapi.core.TopicMapUtils!) line: 167 getIndexManager() Should become getHelperObject(IndexInterface.class) File: query\tolog\predicates\OccurrencePredicate.java line: 59 getParent() Cannot resolve getParent line: 63 getParent() Cannot resolve getParent File: query\tolog\predicates\ReifiesPredicate.java line: 79 getSubject() Replaced just getSubject() -> getSubjectLocators(). ToDo: .iterator().next() or something line: 104 getObjectBySourceLocator( TopicMap.getObjectBySourceLocator -> TopicMapObjectsIndex.getTopicMapObjectBySourceLocator line: 120 getTopicBySubjectIndicator( TopicMap.getTopicBySubjectIndicator -> TopicsIndex.getTopicBySubjectIdentifier line: 130 getObjectBySourceLocator( TopicMap.getObjectBySourceLocator -> TopicMapObjectsIndex.getTopicMapObjectBySourceLocator File: query\tolog\predicates\ResourcePredicate.java line: 15 DataObject DataObject has no equivalent in TMAPI (either an Occurrence or a Variant) line: 56 DataObject DataObject has no equivalent in TMAPI (either an Occurrence or a Variant) line: 57 DataObject DataObject has no equivalent in TMAPI (either an Occurrence or a Variant) line: 72 DataObject DataObject has no equivalent in TMAPI (either an Occurrence or a Variant) line: 73 DataObject DataObject has no equivalent in TMAPI (either an Occurrence or a Variant) line: 80 DataObject DataObject has no equivalent in TMAPI (either an Occurrence or a Variant) line: 81 DataObject DataObject has no equivalent in TMAPI (either an Occurrence or a Variant) line: 95 getIndexManager() Should become getHelperObject(IndexInterface.class) File: query\tolog\predicates\RolePlayerPredicate.java line: 75 getPlayers() AssociationRole can have only one player line: 89 getPlayers() AssociationRole can have only one player line: 101 getPlayers() AssociationRole can have only one player File: query\tolog\predicates\ScopePredicate.java line: 73 getScopedObjects( Could be getScopedObjectsByScopingTopic or ..ByScopingTopics line: 97 getScopedObjects( Could be getScopedObjectsByScopingTopic or ..ByScopingTopics line: 118 getIndexManager() Should become getHelperObject(IndexInterface.class) File: query\tolog\predicates\SourceLocatorsPredicate.java line: 93 getObjectBySourceLocator( TopicMap.getObjectBySourceLocator -> TopicMapObjectsIndex.getTopicMapObjectBySourceLocator File: query\tolog\predicates\SubjectIdentifierPredicate.java line: 94 getTopicBySubjectIndicator( TopicMap.getTopicBySubjectIndicator -> TopicsIndex.getTopicBySubjectIdentifier File: query\tolog\predicates\SubjectLocatorPredicate.java line: 70 getSubject() Replaced just getSubject() -> getSubjectLocators(). ToDo: .iterator().next() or something line: 71 getSubject() Replaced just getSubject() -> getSubjectLocators(). ToDo: .iterator().next() or something line: 82 getSubject() Replaced just getSubject() -> getSubjectLocators(). ToDo: .iterator().next() or something line: 92 getTopicBySubject( TopicMap.getTopicBySubject -> TopicsIndex.getTopicBySubjectLocator line: 103 getSubject() Replaced just getSubject() -> getSubjectLocators(). ToDo: .iterator().next() or something File: query\tolog\predicates\TopicNamePredicate.java line: 82 getParent() Cannot resolve getParent line: 87 getParent() Cannot resolve getParent line: 99 getParent() Cannot resolve getParent line: 114 getIndexManager() Should become getHelperObject(IndexInterface.class) File: query\tolog\predicates\TypePredicate.java line: 170 getIndexManager() Should become getHelperObject(IndexInterface.class) line: 172 getIndexManager() Should become getHelperObject(IndexInterface.class) line: 174 getIndexManager() Should become getHelperObject(IndexInterface.class) File: query\tolog\predicates\ValueLikePredicate.java line: 114 getIndexManager() Should become getHelperObject(IndexInterface.class) File: query\tolog\predicates\ValuePredicate.java line: 22 DataObject DataObject has no equivalent in TMAPI (either an Occurrence or a Variant) line: 28 VariantContainer VariantContainer does not exist in TMAPI (a TopicName is a VariantContainer) line: 90 DataObject DataObject has no equivalent in TMAPI (either an Occurrence or a Variant) line: 91 DataObject DataObject has no equivalent in TMAPI (either an Occurrence or a Variant) line: 125 DataObject DataObject has no equivalent in TMAPI (either an Occurrence or a Variant) line: 126 DataObject DataObject has no equivalent in TMAPI (either an Occurrence or a Variant) line: 152 getIndexManager() Should become getHelperObject(IndexInterface.class) line: 154 getIndexManager() Should become getHelperObject(IndexInterface.class) line: 156 getIndexManager() Should become getHelperObject(IndexInterface.class) line: 189 VariantContainer VariantContainer does not exist in TMAPI (a TopicName is a VariantContainer) File: query\tolog\predicates\VariantPredicate.java line: 22 VariantContainer VariantContainer does not exist in TMAPI (a TopicName is a VariantContainer) line: 117 VariantContainer VariantContainer does not exist in TMAPI (a TopicName is a VariantContainer) line: 117 getParent() Cannot resolve getParent line: 119 getParent() Cannot resolve getParent File: query\tolog\predicates\test\AssociationRolePredicateTest.java line: 65 getParent() Cannot resolve getParent line: 70 getParent() Cannot resolve getParent line: 79 getParent() Cannot resolve getParent line: 80 getParent() Cannot resolve getParent line: 97 getParent() Cannot resolve getParent line: 110 getParent() Cannot resolve getParent File: query\tolog\predicates\test\DirectInstanceOfPredicateTest.java line: 18 TopicMapProvider Usage of TopicMapProvider cannot be translated 1:1 to TopicMapSystem line: 19 TopicMapProvider Usage of TopicMapProvider cannot be translated 1:1 to TopicMapSystem line: 20 TopicMapProvider Usage of TopicMapProvider cannot be translated 1:1 to TopicMapSystem line: 35 TopicMapProvider Usage of TopicMapProvider cannot be translated 1:1 to TopicMapSystem line: 114 TopicMapProvider Usage of TopicMapProvider cannot be translated 1:1 to TopicMapSystem line: 115 TopicMapProvider Usage of TopicMapProvider cannot be translated 1:1 to TopicMapSystem File: query\tolog\predicates\test\DynamicAssociationPredicateTest.java line: 28 TopicMapProvider Usage of TopicMapProvider cannot be translated 1:1 to TopicMapSystem line: 29 TopicMapProvider Usage of TopicMapProvider cannot be translated 1:1 to TopicMapSystem line: 30 TopicMapProvider Usage of TopicMapProvider cannot be translated 1:1 to TopicMapSystem line: 41 TopicMapProvider Usage of TopicMapProvider cannot be translated 1:1 to TopicMapSystem line: 142 TopicMapProvider Usage of TopicMapProvider cannot be translated 1:1 to TopicMapSystem line: 143 TopicMapProvider Usage of TopicMapProvider cannot be translated 1:1 to TopicMapSystem File: query\tolog\predicates\test\PredicateTestBase.java line: 20 TopicMapProvider Usage of TopicMapProvider cannot be translated 1:1 to TopicMapSystem line: 21 TopicMapProvider Usage of TopicMapProvider cannot be translated 1:1 to TopicMapSystem line: 22 TopicMapProvider Usage of TopicMapProvider cannot be translated 1:1 to TopicMapSystem line: 36 TopicMapProvider Usage of TopicMapProvider cannot be translated 1:1 to TopicMapSystem line: 51 TopicMapProvider Usage of TopicMapProvider cannot be translated 1:1 to TopicMapSystem line: 52 TopicMapProvider Usage of TopicMapProvider cannot be translated 1:1 to TopicMapSystem File: query\tolog\predicates\test\TypePredicateTest.java line: 75 getParent() Cannot resolve getParent line: 131 getParent() Cannot resolve getParent File: query\tolog\predicates\test\ValueLikePredicateTest.java line: 25 TopicMapProvider Usage of TopicMapProvider cannot be translated 1:1 to TopicMapSystem line: 26 TopicMapProvider Usage of TopicMapProvider cannot be translated 1:1 to TopicMapSystem line: 107 TopicMapProvider Usage of TopicMapProvider cannot be translated 1:1 to TopicMapSystem line: 108 TopicMapProvider Usage of TopicMapProvider cannot be translated 1:1 to TopicMapSystem line: 113 getIndexManager() Should become getHelperObject(IndexInterface.class) File: query\tolog\predicates\test\ValuePredicateTest.java line: 21 DataObject DataObject has no equivalent in TMAPI (either an Occurrence or a Variant) line: 165 DataObject DataObject has no equivalent in TMAPI (either an Occurrence or a Variant) line: 166 DataObject DataObject has no equivalent in TMAPI (either an Occurrence or a Variant) File: query\tolog\test\AssociationPredicateTest.java line: 28 TopicMapProvider Usage of TopicMapProvider cannot be translated 1:1 to TopicMapSystem line: 29 TopicMapProvider Usage of TopicMapProvider cannot be translated 1:1 to TopicMapSystem line: 30 TopicMapProvider Usage of TopicMapProvider cannot be translated 1:1 to TopicMapSystem line: 42 TopicMapProvider Usage of TopicMapProvider cannot be translated 1:1 to TopicMapSystem line: 144 TopicMapProvider Usage of TopicMapProvider cannot be translated 1:1 to TopicMapSystem line: 145 TopicMapProvider Usage of TopicMapProvider cannot be translated 1:1 to TopicMapSystem File: query\tolog\test\MemoryQueryEvaluatorImplTest.java line: 28 TopicMapProvider Usage of TopicMapProvider cannot be translated 1:1 to TopicMapSystem line: 29 TopicMapProvider Usage of TopicMapProvider cannot be translated 1:1 to TopicMapSystem line: 30 TopicMapProvider Usage of TopicMapProvider cannot be translated 1:1 to TopicMapSystem line: 41 TopicMapProvider Usage of TopicMapProvider cannot be translated 1:1 to TopicMapSystem line: 77 TopicMapProvider Usage of TopicMapProvider cannot be translated 1:1 to TopicMapSystem line: 107 TopicMapProvider Usage of TopicMapProvider cannot be translated 1:1 to TopicMapSystem line: 108 TopicMapProvider Usage of TopicMapProvider cannot be translated 1:1 to TopicMapSystem line: 109 TopicMapProvider Usage of TopicMapProvider cannot be translated 1:1 to TopicMapSystem File: query\tolog\test\ProjectionTest.java line: 31 TopicMapProvider Usage of TopicMapProvider cannot be translated 1:1 to TopicMapSystem line: 32 TopicMapProvider Usage of TopicMapProvider cannot be translated 1:1 to TopicMapSystem line: 33 TopicMapProvider Usage of TopicMapProvider cannot be translated 1:1 to TopicMapSystem line: 45 TopicMapProvider Usage of TopicMapProvider cannot be translated 1:1 to TopicMapSystem line: 103 TopicMapProvider Usage of TopicMapProvider cannot be translated 1:1 to TopicMapSystem line: 104 TopicMapProvider Usage of TopicMapProvider cannot be translated 1:1 to TopicMapSystem File: query\tolog\test\SortingTest.java line: 23 TopicMapProvider Usage of TopicMapProvider cannot be translated 1:1 to TopicMapSystem line: 24 TopicMapProvider Usage of TopicMapProvider cannot be translated 1:1 to TopicMapSystem line: 26 IDGeneratorFactory Has become org.tmapi.core.utils.IDGeneratorFactory line: 34 TopicMapProvider Usage of TopicMapProvider cannot be translated 1:1 to TopicMapSystem line: 43 TopicMapProvider Usage of TopicMapProvider cannot be translated 1:1 to TopicMapSystem line: 44 TopicMapProvider Usage of TopicMapProvider cannot be translated 1:1 to TopicMapSystem line: 45 IDGeneratorFactory Has become org.tmapi.core.utils.IDGeneratorFactory line: 126 createName Must become "createTopicName" line: 128 createName Must become "createTopicName" line: 130 createName Must become "createTopicName" File: query\tolog\test\TologParserTest.java line: 258 createMember Must become "createAssociationRole" line: 261 createMember Must become "createAssociationRole" File: query\tolog\test\TologParserTestBase.java line: 16 TopicMapProvider Usage of TopicMapProvider cannot be translated 1:1 to TopicMapSystem line: 17 TopicMapProvider Usage of TopicMapProvider cannot be translated 1:1 to TopicMapSystem line: 18 TopicMapProvider Usage of TopicMapProvider cannot be translated 1:1 to TopicMapSystem line: 21 IDGeneratorFactory Has become org.tmapi.core.utils.IDGeneratorFactory line: 38 TopicMapProvider Usage of TopicMapProvider cannot be translated 1:1 to TopicMapSystem line: 49 TopicMapProvider Usage of TopicMapProvider cannot be translated 1:1 to TopicMapSystem line: 50 TopicMapProvider Usage of TopicMapProvider cannot be translated 1:1 to TopicMapSystem line: 57 IDGeneratorFactory Has become org.tmapi.core.utils.IDGeneratorFactory |
From: Lars H. <lh...@us...> - 2005-03-06 18:15:55
|
Update of /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5563/src/org/tmapiutils/query/tolog/predicates/test Modified Files: DirectInstanceOfPredicateTest.java DynamicAssociationPredicateTest.java PredicateTestBase.java ResourcePredicateTest.java ValueLikePredicateTest.java Log Message: org.tm4j.net.Locator -> org.tmapi.core.Locator Index: ResourcePredicateTest.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test/ResourcePredicateTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ResourcePredicateTest.java 6 Mar 2005 17:33:23 -0000 1.1 --- ResourcePredicateTest.java 6 Mar 2005 18:15:43 -0000 1.2 *************** *** 15,19 **** import java.util.List; ! import org.tm4j.net.Locator; import org.tmapiutils.query.tolog.parser.Variable; import org.tmapiutils.query.tolog.predicates.ResourcePredicate; --- 15,19 ---- import java.util.List; ! import org.tmapi.core.Locator; import org.tmapiutils.query.tolog.parser.Variable; import org.tmapiutils.query.tolog.predicates.ResourcePredicate; *************** *** 139,142 **** --- 139,145 ---- /* * $Log$ + * Revision 1.2 2005/03/06 18:15:43 lheuer + * org.tm4j.net.Locator -> org.tmapi.core.Locator + * * Revision 1.1 2005/03/06 17:33:23 lheuer * Initial tolog import Index: PredicateTestBase.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test/PredicateTestBase.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PredicateTestBase.java 6 Mar 2005 17:33:23 -0000 1.1 --- PredicateTestBase.java 6 Mar 2005 18:15:43 -0000 1.2 *************** *** 14,18 **** import junit.framework.TestCase; ! import org.tm4j.net.Locator; import org.tmapiutils.query.tolog.parser.Predicate; import org.tmapiutils.query.tolog.utils.TologContext; --- 14,18 ---- import junit.framework.TestCase; ! import org.tmapi.core.Locator; import org.tmapiutils.query.tolog.parser.Predicate; import org.tmapiutils.query.tolog.utils.TologContext; *************** *** 63,66 **** --- 63,69 ---- /* * $Log$ + * Revision 1.2 2005/03/06 18:15:43 lheuer + * org.tm4j.net.Locator -> org.tmapi.core.Locator + * * Revision 1.1 2005/03/06 17:33:23 lheuer * Initial tolog import Index: DirectInstanceOfPredicateTest.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test/DirectInstanceOfPredicateTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** DirectInstanceOfPredicateTest.java 6 Mar 2005 17:33:23 -0000 1.1 --- DirectInstanceOfPredicateTest.java 6 Mar 2005 18:15:43 -0000 1.2 *************** *** 9,13 **** import java.util.List; ! import org.tm4j.net.Locator; import org.tmapiutils.query.tolog.parser.Predicate; import org.tmapiutils.query.tolog.parser.Variable; --- 9,13 ---- import java.util.List; ! import org.tmapi.core.Locator; import org.tmapiutils.query.tolog.parser.Predicate; import org.tmapiutils.query.tolog.parser.Variable; Index: DynamicAssociationPredicateTest.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test/DynamicAssociationPredicateTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** DynamicAssociationPredicateTest.java 6 Mar 2005 17:33:23 -0000 1.1 --- DynamicAssociationPredicateTest.java 6 Mar 2005 18:15:43 -0000 1.2 *************** *** 18,22 **** import org.apache.log4j.BasicConfigurator; ! import org.tm4j.net.Locator; import org.tmapiutils.query.tolog.parser.ClauseList; import org.tmapiutils.query.tolog.parser.PlayerRoleVarPair; --- 18,22 ---- import org.apache.log4j.BasicConfigurator; ! import org.tmapi.core.Locator; import org.tmapiutils.query.tolog.parser.ClauseList; import org.tmapiutils.query.tolog.parser.PlayerRoleVarPair; *************** *** 155,158 **** --- 155,161 ---- /* * $Log$ + * Revision 1.2 2005/03/06 18:15:43 lheuer + * org.tm4j.net.Locator -> org.tmapi.core.Locator + * * Revision 1.1 2005/03/06 17:33:23 lheuer * Initial tolog import Index: ValueLikePredicateTest.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test/ValueLikePredicateTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ValueLikePredicateTest.java 6 Mar 2005 17:33:23 -0000 1.1 --- ValueLikePredicateTest.java 6 Mar 2005 18:15:43 -0000 1.2 *************** *** 15,19 **** import java.util.Iterator; ! import org.tm4j.net.Locator; import org.tmapiutils.query.tolog.parser.Predicate; import org.tmapiutils.query.tolog.parser.Variable; --- 15,19 ---- import java.util.Iterator; ! import org.tmapi.core.Locator; import org.tmapiutils.query.tolog.parser.Predicate; import org.tmapiutils.query.tolog.parser.Variable; *************** *** 121,124 **** --- 121,127 ---- /* * $Log$ + * Revision 1.2 2005/03/06 18:15:43 lheuer + * org.tm4j.net.Locator -> org.tmapi.core.Locator + * * Revision 1.1 2005/03/06 17:33:23 lheuer * Initial tolog import |
From: Lars H. <lh...@us...> - 2005-03-06 18:14:21
|
Update of /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5191/src/org/tmapiutils/query/tolog/predicates Modified Files: BaseLocatorPredicate.java ReifiesPredicate.java ResourcePredicate.java SourceLocatorsPredicate.java SubjectIdentifierPredicate.java SubjectLocatorPredicate.java Log Message: org.tm4j.net.Locator -> org.tmapi.core.Locator Index: SubjectLocatorPredicate.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/SubjectLocatorPredicate.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SubjectLocatorPredicate.java 6 Mar 2005 17:30:00 -0000 1.1 --- SubjectLocatorPredicate.java 6 Mar 2005 18:14:09 -0000 1.2 *************** *** 8,12 **** import java.util.List; ! import org.tm4j.net.Locator; import org.tmapiutils.query.tolog.TologProcessingException; import org.tmapiutils.query.tolog.parser.Variable; --- 8,12 ---- import java.util.List; ! import org.tmapi.core.Locator; import org.tmapiutils.query.tolog.TologProcessingException; import org.tmapiutils.query.tolog.parser.Variable; Index: SourceLocatorsPredicate.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/SourceLocatorsPredicate.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SourceLocatorsPredicate.java 6 Mar 2005 17:30:00 -0000 1.1 --- SourceLocatorsPredicate.java 6 Mar 2005 18:14:09 -0000 1.2 *************** *** 8,12 **** import java.util.List; ! import org.tm4j.net.Locator; import org.tmapiutils.query.tolog.TologProcessingException; import org.tmapiutils.query.tolog.parser.Variable; --- 8,12 ---- import java.util.List; ! import org.tmapi.core.Locator; import org.tmapiutils.query.tolog.TologProcessingException; import org.tmapiutils.query.tolog.parser.Variable; Index: ReifiesPredicate.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/ReifiesPredicate.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ReifiesPredicate.java 6 Mar 2005 17:30:00 -0000 1.1 --- ReifiesPredicate.java 6 Mar 2005 18:14:09 -0000 1.2 *************** *** 15,19 **** import java.util.List; ! import org.tm4j.net.Locator; import org.tmapiutils.query.tolog.TologProcessingException; import org.tmapiutils.query.tolog.parser.Variable; --- 15,19 ---- import java.util.List; ! import org.tmapi.core.Locator; import org.tmapiutils.query.tolog.TologProcessingException; import org.tmapiutils.query.tolog.parser.Variable; *************** *** 138,141 **** --- 138,144 ---- /* * $Log$ + * Revision 1.2 2005/03/06 18:14:09 lheuer + * org.tm4j.net.Locator -> org.tmapi.core.Locator + * * Revision 1.1 2005/03/06 17:30:00 lheuer * Initial tolog import Index: BaseLocatorPredicate.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/BaseLocatorPredicate.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** BaseLocatorPredicate.java 6 Mar 2005 17:29:58 -0000 1.1 --- BaseLocatorPredicate.java 6 Mar 2005 18:14:09 -0000 1.2 *************** *** 14,18 **** import java.util.List; ! import org.tm4j.net.Locator; import org.tmapiutils.query.tolog.TologProcessingException; import org.tmapiutils.query.tolog.parser.Variable; --- 14,18 ---- import java.util.List; ! import org.tmapi.core.Locator; import org.tmapiutils.query.tolog.TologProcessingException; import org.tmapiutils.query.tolog.parser.Variable; *************** *** 65,68 **** --- 65,71 ---- /* * $Log$ + * Revision 1.2 2005/03/06 18:14:09 lheuer + * org.tm4j.net.Locator -> org.tmapi.core.Locator + * * Revision 1.1 2005/03/06 17:29:58 lheuer * Initial tolog import Index: SubjectIdentifierPredicate.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/SubjectIdentifierPredicate.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SubjectIdentifierPredicate.java 6 Mar 2005 17:30:00 -0000 1.1 --- SubjectIdentifierPredicate.java 6 Mar 2005 18:14:09 -0000 1.2 *************** *** 8,12 **** import java.util.List; ! import org.tm4j.net.Locator; import org.tmapiutils.query.tolog.TologProcessingException; import org.tmapiutils.query.tolog.parser.Variable; --- 8,12 ---- import java.util.List; ! import org.tmapi.core.Locator; import org.tmapiutils.query.tolog.TologProcessingException; import org.tmapiutils.query.tolog.parser.Variable; Index: ResourcePredicate.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/ResourcePredicate.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ResourcePredicate.java 6 Mar 2005 17:30:00 -0000 1.1 --- ResourcePredicate.java 6 Mar 2005 18:14:09 -0000 1.2 *************** *** 8,12 **** import java.util.List; ! import org.tm4j.net.Locator; import org.tmapiutils.query.tolog.TologParserException; import org.tmapiutils.query.tolog.TologProcessingException; --- 8,12 ---- import java.util.List; ! import org.tmapi.core.Locator; import org.tmapiutils.query.tolog.TologParserException; import org.tmapiutils.query.tolog.TologProcessingException; |
From: Lars H. <lh...@us...> - 2005-03-06 18:08:38
|
Update of /cvsroot/tmapi-utils/tmapi-utils/utils In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3658/utils Modified Files: terminology.py Log Message: Marked "LocatorFactory" as 'critical' Index: terminology.py =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/utils/terminology.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** terminology.py 6 Mar 2005 18:05:16 -0000 1.3 --- terminology.py 6 Mar 2005 18:08:26 -0000 1.4 *************** *** 99,103 **** 'TopicMapUtils':'Usage of org.tm4j.topicmap.TopicMapUtils (has become org.tmapi.core.TopicMapUtils!)', 'IDGeneratorFactory':'Has become org.tmapi.core.utils.IDGeneratorFactory', ! 'LocatorFactoryException':'Has become org.tmapi.core.LocatorFactoryException. Has no TMAPI equivalent', # Topic 'getSubject()':'Replaced just getSubject() -> getSubjectLocators(). ToDo: .iterator().next() or something', --- 99,103 ---- 'TopicMapUtils':'Usage of org.tm4j.topicmap.TopicMapUtils (has become org.tmapi.core.TopicMapUtils!)', 'IDGeneratorFactory':'Has become org.tmapi.core.utils.IDGeneratorFactory', ! 'LocatorFactory':'Has become org.tmapi.core.LocatorFactory<Exception>. Has no TMAPI equivalent', # Topic 'getSubject()':'Replaced just getSubject() -> getSubjectLocators(). ToDo: .iterator().next() or something', |
From: Lars H. <lh...@us...> - 2005-03-06 18:05:29
|
Update of /cvsroot/tmapi-utils/tmapi-utils/utils In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2744/utils Modified Files: terminology.py Log Message: Marked "LocatorFactoryException" as 'critical' Index: terminology.py =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/utils/terminology.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** terminology.py 6 Mar 2005 18:00:47 -0000 1.2 --- terminology.py 6 Mar 2005 18:05:16 -0000 1.3 *************** *** 99,102 **** --- 99,103 ---- 'TopicMapUtils':'Usage of org.tm4j.topicmap.TopicMapUtils (has become org.tmapi.core.TopicMapUtils!)', 'IDGeneratorFactory':'Has become org.tmapi.core.utils.IDGeneratorFactory', + 'LocatorFactoryException':'Has become org.tmapi.core.LocatorFactoryException. Has no TMAPI equivalent', # Topic 'getSubject()':'Replaced just getSubject() -> getSubjectLocators(). ToDo: .iterator().next() or something', |
From: Lars H. <lh...@us...> - 2005-03-06 18:01:00
|
Update of /cvsroot/tmapi-utils/tmapi-utils/utils In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1717/utils Modified Files: terminology.py Log Message: Added translation: org.tm4j.net.Locator -> org.tmapi.core.Locator Index: terminology.py =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/utils/terminology.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** terminology.py 6 Mar 2005 17:10:31 -0000 1.1 --- terminology.py 6 Mar 2005 18:00:47 -0000 1.2 *************** *** 18,21 **** --- 18,22 ---- classes = { + 'org.tm4j.net.Locator':'org.tmapi.core.Locator', 'BaseNameDataIndex':'TopicNamesIndex', 'TopicNameDataIndex':'TopicNamesIndex', # if BaseName -> TopicName replacement |
Update of /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/utils In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27277/src/org/tmapiutils/query/tolog/utils Added Files: DefaultRowComparator.java InvertedComparator.java ReferenceUtils.java RowComparator.java TologContext.java VariableSet.java Log Message: Initial tolog import --- NEW FILE: InvertedComparator.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/utils/InvertedComparator.java,v 1.1 2005/03/06 17:35:06 lheuer Exp $ */ package org.tmapiutils.query.tolog.utils; import java.util.Comparator; /** * * @author Kal Ahmed (ka...@te...) */ 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; } } /* * $Log: InvertedComparator.java,v $ * Revision 1.1 2005/03/06 17:35:06 lheuer * Initial tolog import * * Revision 1.1 2004/06/07 20:32:16 kal_ahmed * Completed work on projection and sorting. Performed a bit more code reorganisation. Added DirectInstanceOfPredicate. * * Revision 1.1 2004/05/30 22:08:25 kal_ahmed * Initial version of tolog 1.0 engine * */ --- NEW FILE: ReferenceUtils.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/utils/ReferenceUtils.java,v 1.1 2005/03/06 17:35:06 lheuer Exp $ */ package org.tmapiutils.query.tolog.utils; import java.util.Iterator; import org.tm4j.net.Locator; import org.tmapi.core.TopicMapObject; /** * @author Kal * * Describe ReferenceUtils here. */ 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.getID(); } else { return ret; } } } /* * $Log: ReferenceUtils.java,v $ * Revision 1.1 2005/03/06 17:35:06 lheuer * Initial tolog import * * Revision 1.2 2004/06/09 21:12:19 kal_ahmed * Added standard source file header and footer. * */ --- NEW FILE: RowComparator.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/utils/RowComparator.java,v 1.1 2005/03/06 17:35:06 lheuer Exp $ */ package org.tmapiutils.query.tolog.utils; import java.util.Comparator; import java.util.List; /** * * @author Kal Ahmed (ka...@te...) */ 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); } /* * $Log: RowComparator.java,v $ * Revision 1.1 2005/03/06 17:35:06 lheuer * Initial tolog import * * Revision 1.1 2004/06/07 20:32:17 kal_ahmed * Completed work on projection and sorting. Performed a bit more code reorganisation. Added DirectInstanceOfPredicate. * * Revision 1.1 2004/05/30 22:08:25 kal_ahmed * Initial version of tolog 1.0 engine * */ --- NEW FILE: TologContext.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/utils/TologContext.java,v 1.1 2005/03/06 17:35:06 lheuer Exp $ */ 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 (ka...@te...) */ 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; } } } /* * $Log: TologContext.java,v $ * Revision 1.1 2005/03/06 17:35:06 lheuer * Initial tolog import * * Revision 1.3 2004/07/16 13:51:53 kal_ahmed * Fixes for tolog engine handling of rules and rule-recursion. * * Revision 1.2 2004/06/16 21:21:44 kal_ahmed * Tolog queries may now contain replaceable references specified in an Object array parameter to the QueryEvaluator at evaluation time. * * Revision 1.1 2004/06/13 19:44:31 kal_ahmed * Added a fix and test for handling recursive rules definitions. * */ --- NEW FILE: DefaultRowComparator.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/utils/DefaultRowComparator.java,v 1.1 2005/03/06 17:35:06 lheuer Exp $ */ 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 (ka...@te...) */ 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).getID().compareTo(((TopicMapObject)o2).getID()); } } } return ret; } } /* * $Log: DefaultRowComparator.java,v $ * Revision 1.1 2005/03/06 17:35:06 lheuer * Initial tolog import * * Revision 1.2 2004/06/27 17:47:40 kal_ahmed * Fixed imports. * * Revision 1.1 2004/06/07 20:32:15 kal_ahmed * Completed work on projection and sorting. Performed a bit more code reorganisation. Added DirectInstanceOfPredicate. * * Revision 1.1 2004/05/30 22:08:25 kal_ahmed * Initial version of tolog 1.0 engine * */ --- NEW FILE: VariableSet.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/utils/VariableSet.java,v 1.1 2005/03/06 17:35:06 lheuer Exp $ */ 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 (ka...@te...) */ 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).getID()); } 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); } } } /* * $Log: VariableSet.java,v $ * Revision 1.1 2005/03/06 17:35:06 lheuer * Initial tolog import * * Revision 1.3 2004/07/16 13:51:53 kal_ahmed * Fixes for tolog engine handling of rules and rule-recursion. * * Revision 1.2 2004/06/09 20:20:31 kal_ahmed * Major reworking of the predicate interfaces and internal implementation of VariableSet to reduce the use of HashMaps. * * Revision 1.1 2004/06/07 20:32:17 kal_ahmed * Completed work on projection and sorting. Performed a bit more code reorganisation. Added DirectInstanceOfPredicate. * * Revision 1.1 2004/05/30 22:08:25 kal_ahmed * Initial version of tolog 1.0 engine * */ |
From: Lars H. <lh...@us...> - 2005-03-06 17:34:49
|
Update of /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/test/backends In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27141/src/org/tmapiutils/query/tolog/test/backends Added Files: BasicTests.java QueryTestBase.java Log Message: Initial tolog import --- NEW FILE: QueryTestBase.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/test/backends/QueryTestBase.java,v 1.1 2005/03/06 17:34:39 lheuer Exp $ */ 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.tm4j.net.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 * * Describe QueryTestBase here. */ 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).getID()); } 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.getID().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; } } /* * $Log: QueryTestBase.java,v $ * Revision 1.1 2005/03/06 17:34:39 lheuer * Initial tolog import * * Revision 1.8 2004/07/21 08:45:35 kal_ahmed * Fixed bugs in reifies predicate. * * Revision 1.7 2004/07/19 14:52:41 kal_ahmed * More fixes to processing of recursive rules. ClauseList now aborts when the input parameter list becomes empty. * * Revision 1.6 2004/07/16 13:51:52 kal_ahmed * Fixes for tolog engine handling of rules and rule-recursion. * * Revision 1.5 2004/06/21 18:42:28 kal_ahmed * Improved exception propagation. * * Revision 1.4 2004/06/20 14:12:31 kal_ahmed * Copied TologRsultsSet interface and TologFragmentBuilder implementation from org.tm4j.tolog to this package. * * Revision 1.3 2004/06/15 20:00:35 kal_ahmed * Added a few more tests over the block-world topic map. * * Revision 1.2 2004/06/15 19:44:48 kal_ahmed * Resynced expected results with actual topic map. * */ --- NEW FILE: BasicTests.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/test/backends/BasicTests.java,v 1.1 2005/03/06 17:34:39 lheuer Exp $ */ 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 * * Describe BasicTests here. */ 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"} }); } } /* * $Log: BasicTests.java,v $ * Revision 1.1 2005/03/06 17:34:39 lheuer * Initial tolog import * * Revision 1.8 2004/07/21 08:45:35 kal_ahmed * Fixed bugs in reifies predicate. * * Revision 1.7 2004/07/19 16:02:43 kal_ahmed * Fixed tests to properly initialize input variable set. * * Revision 1.6 2004/07/19 14:52:40 kal_ahmed * More fixes to processing of recursive rules. ClauseList now aborts when the input parameter list becomes empty. * * Revision 1.5 2004/07/16 13:51:37 kal_ahmed * Fixes for tolog engine handling of rules and rule-recursion. * * Revision 1.4 2004/07/14 21:42:25 kal_ahmed * Parser now supports a variable for the association type in a dynamic association predicate. * * Revision 1.3 2004/06/15 20:00:35 kal_ahmed * Added a few more tests over the block-world topic map. * */ |
Update of /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26910/src/org/tmapiutils/query/tolog/test Added 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: Initial tolog import --- NEW FILE: AssociationPredicateTest.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/test/AssociationPredicateTest.java,v 1.1 2005/03/06 17:34:06 lheuer Exp $ */ package org.tmapiutils.query.tolog.test; import java.io.StringReader; import java.util.ArrayList; import java.util.List; import junit.framework.TestCase; import org.apache.log4j.BasicConfigurator; import org.tm4j.net.Locator; 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; import org.tmapi.core.TopicMap; import org.tmapi.core.TopicMapProvider; import org.tmapi.core.TopicMapProviderFactory; import org.tmapi.core.memory.TopicMapProviderFactoryImpl; import org.tmapi.core.source.SerializedTopicMapSource; import org.tmapi.core.utils.LTMBuilder; /** * * @author Kal Ahmed (ka...@te...) */ public class AssociationPredicateTest extends TestCase { private TopicMap m_tm; private TopicMapProvider m_provider; /** * 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.getTopicByID("worksfor")); params.add(new PlayerRoleVarPair(m_tm.getTopicByID("kal"), m_tm.getTopicByID("employee"))); params.add(new PlayerRoleVarPair(new Variable("A"), m_tm.getTopicByID("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(m_tm.getTopicByID("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.getTopicByID("worksfor")); params.add(new PlayerRoleVarPair(new Variable("PERSON"), m_tm.getTopicByID("employee"))); params.add(new PlayerRoleVarPair(new Variable("COMPANY"), m_tm.getTopicByID("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(m_tm.getTopicByID("kal")) || row.get(0).equals(m_tm.getTopicByID("fred"))); assertTrue( row.get(1).equals(m_tm.getTopicByID("techquila")) || row.get(1).equals(m_tm.getTopicByID("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"), m_tm.getTopicByID("employee"))); params.add(new PlayerRoleVarPair(new Variable("COMPANY"), m_tm.getTopicByID("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), m_tm.getTopicByID("worksfor")); assertTrue( row.get(1).equals(m_tm.getTopicByID("kal")) || row.get(1).equals(m_tm.getTopicByID("fred"))); assertTrue( row.get(2).equals(m_tm.getTopicByID("techquila")) || row.get(2).equals(m_tm.getTopicByID("bigcorp"))); } } /* (non-Javadoc) * @see junit.framework.TestCase#setUp() */ 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); assertNotNull(m_tm.getTopicByID("worksfor")); } private static final String TESTMAP ="worksfor(kal:employee, techquila:employer)\n" + "worksfor(fred:employee, bigcorp:employer)\n"; } /* * $Log: AssociationPredicateTest.java,v $ * Revision 1.1 2005/03/06 17:34:06 lheuer * Initial tolog import * * Revision 1.6 2004/07/19 16:02:42 kal_ahmed * Fixed tests to properly initialize input variable set. * * Revision 1.5 2004/06/14 20:10:33 kal_ahmed * Updated test code to work with new Predicate and Clause interfaces. * * Revision 1.4 2004/06/09 20:20:31 kal_ahmed * Major reworking of the predicate interfaces and internal implementation of VariableSet to reduce the use of HashMaps. * * Revision 1.3 2004/06/03 20:04:56 kal_ahmed * Completed initial package restructuring. * * Revision 1.2 2004/06/03 19:55:17 kal_ahmed * Created utils package to hold common utility classes for Tolog implementations. * * Revision 1.1 2004/05/30 22:08:25 kal_ahmed * Initial version of tolog 1.0 engine * */ --- NEW FILE: ImportTest.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/test/ImportTest.java,v 1.1 2005/03/06 17:34:06 lheuer Exp $ */ 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 * * Describe ImportTest here. */ 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); } } /* * $Log: ImportTest.java,v $ * Revision 1.1 2005/03/06 17:34:06 lheuer * Initial tolog import * * Revision 1.4 2004/06/13 17:18:00 kal_ahmed * Added registration of builtin predicates. Fixed rule expansion code to handle player/role pairs correctly. * * Revision 1.3 2004/06/09 21:12:19 kal_ahmed * Added standard source file header and footer. * */ --- NEW FILE: RuleTest.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/test/RuleTest.java,v 1.1 2005/03/06 17:34:06 lheuer Exp $ */ 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 * * Describe RuleTest here. */ 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)); } } /* * $Log: RuleTest.java,v $ * Revision 1.1 2005/03/06 17:34:06 lheuer * Initial tolog import * * Revision 1.8 2004/07/19 16:02:42 kal_ahmed * Fixed tests to properly initialize input variable set. * * Revision 1.7 2004/06/16 21:21:44 kal_ahmed * Tolog queries may now contain replaceable references specified in an Object array parameter to the QueryEvaluator at evaluation time. * * Revision 1.6 2004/06/14 20:10:33 kal_ahmed * Updated test code to work with new Predicate and Clause interfaces. * * Revision 1.5 2004/06/09 21:12:19 kal_ahmed * Added standard source file header and footer. * */ --- NEW FILE: SortingTest.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/test/SortingTest.java,v 1.1 2005/03/06 17:34:06 lheuer Exp $ */ package org.tmapiutils.query.tolog.test; import java.util.ArrayList; import junit.framework.TestCase; import org.tm4j.net.Locator; import org.tmapiutils.query.tolog.parser.Sorting; import org.tmapiutils.query.tolog.parser.Variable; import org.tmapi.core.TopicName; import org.tmapi.core.Topic; import org.tmapi.core.TopicMap; import org.tmapi.core.TopicMapProvider; import org.tmapi.core.TopicMapProviderFactory; import org.tmapi.core.utils.IDGenerator; import org.tmapi.core.utils.IDGeneratorFactory; /** * * @author Kal Ahmed (ka...@te...) */ public class SortingTest extends TestCase { private TopicMapProvider m_provider; private IDGenerator m_idgen; /** * Constructor for SortingTest. * @param arg0 */ public SortingTest(String arg0) throws Exception { super(arg0); TopicMapProviderFactory tmpf = TopicMapProviderFactory.newInstance(); m_provider = tmpf.newTopicMapProvider(); m_idgen = IDGeneratorFactory.newIDGenerator(); } 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"); ArrayList cols = new ArrayList(); cols.add(new Variable("A")); ArrayList rows = new ArrayList(); ArrayList row1 = new ArrayList(); row1.add(t3); rows.add(row1); ArrayList row2 = new ArrayList(); row2.add(t1); rows.add(row2); ArrayList row3 = new ArrayList(); row3.add(t2); 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"); 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.getID()); return m_provider.createTopicMap(loc); } } /* * $Log: SortingTest.java,v $ * Revision 1.1 2005/03/06 17:34:06 lheuer * Initial tolog import * * Revision 1.2 2004/06/03 20:04:56 kal_ahmed * Completed initial package restructuring. * * Revision 1.1 2004/05/30 22:08:25 kal_ahmed * Initial version of tolog 1.0 engine * */ --- NEW FILE: ProjectionTest.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/test/ProjectionTest.java,v 1.1 2005/03/06 17:34:06 lheuer Exp $ */ package org.tmapiutils.query.tolog.test; import java.io.StringReader; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import junit.framework.TestCase; import org.tm4j.net.Locator; 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; import org.tmapi.core.Topic; import org.tmapi.core.TopicMap; import org.tmapi.core.TopicMapProvider; import org.tmapi.core.TopicMapProviderFactory; import org.tmapi.core.memory.TopicMapProviderFactoryImpl; import org.tmapi.core.source.SerializedTopicMapSource; import org.tmapi.core.utils.LTMBuilder; /** * * @author Kal Ahmed (ka...@te...) */ public class ProjectionTest extends TestCase { private TopicMap m_tm; private TopicMapProvider m_provider; /** * 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(m_tm.getTopicByID("contains")); params.add(new PlayerRoleVarPair(new Variable("CONTAINER"), m_tm.getTopicByID("container"))); params.add(new PlayerRoleVarPair(new Variable("CONTAINEE"), m_tm.getTopicByID("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(m_tm.getTopicByID("europe"))) { assertEquals(new Integer(3), row.get(1)); } else if (row.get(0).equals(m_tm.getTopicByID("asia"))) { assertEquals(new Integer(2), row.get(1)); } } } /* * @see TestCase#setUp() */ protected void setUp() throws Exception { super.setUp(); 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); } 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"; } /* * $Log: ProjectionTest.java,v $ * Revision 1.1 2005/03/06 17:34:06 lheuer * Initial tolog import * * Revision 1.7 2004/07/19 16:02:42 kal_ahmed * Fixed tests to properly initialize input variable set. * * Revision 1.6 2004/06/14 20:10:33 kal_ahmed * Updated test code to work with new Predicate and Clause interfaces. * * Revision 1.5 2004/06/09 20:20:31 kal_ahmed * Major reworking of the predicate interfaces and internal implementation of VariableSet to reduce the use of HashMaps. * * Revision 1.4 2004/06/07 20:32:11 kal_ahmed * Completed work on projection and sorting. Performed a bit more code reorganisation. Added DirectInstanceOfPredicate. * * Revision 1.3 2004/06/03 20:04:56 kal_ahmed * Completed initial package restructuring. * * Revision 1.2 2004/06/03 19:55:17 kal_ahmed * Created utils package to hold common utility classes for Tolog implementations. * * Revision 1.1 2004/05/30 22:08:25 kal_ahmed * Initial version of tolog 1.0 engine * */ --- NEW FILE: OrClauseTest.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/test/OrClauseTest.java,v 1.1 2005/03/06 17:34:06 lheuer Exp $ */ package org.tmapiutils.query.tolog.test; import java.util.ArrayList; import java.util.List; import junit.framework.TestCase; import org.tmapiutils.query.tolog.parser.ClauseList; import org.tmapiutils.query.tolog.parser.OrClause; import org.tmapiutils.query.tolog.parser.Predicate; import org.tmapiutils.query.tolog.parser.Variable; import org.tmapiutils.query.tolog.utils.TologContext; import org.tmapiutils.query.tolog.utils.VariableSet; /** * * @author Kal Ahmed (ka...@te...) */ public class OrClauseTest extends TestCase { /** * Constructor for OrClauseTest. * @param arg0 */ public OrClauseTest(String arg0) { super(arg0); } public static void main(String[] args) { junit.textui.TestRunner.run(OrClauseTest.class); } public void testOrClause() throws Exception { ClauseList ac1 = new ClauseList(); Predicate p1 = new Increment(); ArrayList params1 = new ArrayList(); params1.add(new Integer(1)); params1.add(new Variable("A")); p1.setParameters(params1); ac1.addPredicate(p1); ClauseList ac2 = new ClauseList(); Predicate p2 = new Increment(); ArrayList params2 = new ArrayList(); params2.add(new Integer(4)); params2.add(new Variable("A")); p2.setParameters(params2); ac2.addPredicate(p2); OrClause oc = new OrClause(); oc.add(ac1); oc.add(ac2); VariableSet in = new VariableSet(); in.addColumn(new Variable("A")); in.addRow(in.getColumns()); VariableSet ret = oc.execute(in, new TologContext()); assertEquals(2, ret.size()); List row = ret.getRow(0); assertNotNull(row); assertEquals(1, row.size()); assertEquals(new Integer(2), (Integer)row.get(0)); row = ret.getRow(1); assertNotNull(row); assertEquals(1, row.size()); assertEquals(new Integer(5), (Integer)row.get(0)); } } /* * $Log: OrClauseTest.java,v $ * Revision 1.1 2005/03/06 17:34:06 lheuer * Initial tolog import * * Revision 1.6 2004/07/19 16:02:42 kal_ahmed * Fixed tests to properly initialize input variable set. * * Revision 1.5 2004/06/14 20:10:33 kal_ahmed * Updated test code to work with new Predicate and Clause interfaces. * * Revision 1.4 2004/06/09 20:20:31 kal_ahmed * Major reworking of the predicate interfaces and internal implementation of VariableSet to reduce the use of HashMaps. * * Revision 1.3 2004/06/03 20:04:56 kal_ahmed * Completed initial package restructuring. * * Revision 1.2 2004/06/03 19:55:17 kal_ahmed * Created utils package to hold common utility classes for Tolog implementations. * * Revision 1.1 2004/05/30 22:08:25 kal_ahmed * Initial version of tolog 1.0 engine * */ --- NEW FILE: NotClauseTest.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/test/NotClauseTest.java,v 1.1 2005/03/06 17:34:06 lheuer Exp $ */ package org.tmapiutils.query.tolog.test; import java.util.ArrayList; import java.util.List; import junit.framework.TestCase; import org.tmapiutils.query.tolog.parser.ClauseList; import org.tmapiutils.query.tolog.parser.NotClause; import org.tmapiutils.query.tolog.parser.Predicate; import org.tmapiutils.query.tolog.parser.Variable; import org.tmapiutils.query.tolog.utils.TologContext; import org.tmapiutils.query.tolog.utils.VariableSet; /** * * @author Kal Ahmed (ka...@te...) */ public class NotClauseTest extends TestCase { /** * Constructor for NotClauseTest. * @param arg0 */ public NotClauseTest(String arg0) { super(arg0); } public static void main(String[] args) { junit.textui.TestRunner.run(NotClauseTest.class); } public void testNotClause() throws Exception { ClauseList ac1 = new ClauseList(); Predicate p1 = new Increment(); List params1 = new ArrayList(); params1.add(new Variable("A")); params1.add(new Variable("B")); p1.setParameters(params1); ac1.addPredicate(p1); NotClause nc = new NotClause(); nc.setTest(ac1); VariableSet in = new VariableSet(); in.addColumn(new Variable("A")); in.addColumn(new Variable("B")); in.addRow(new Object[] { new Integer(1), new Integer(2)}); in.addRow(new Object[] { new Integer(1), new Integer(3)}); VariableSet ret = nc.execute(in, new TologContext()); assertEquals(2, ret.getColumns().size()); assertEquals(1, ret.getRows().size()); assertEquals(new Integer(1), ret.getRow(0).get(0)); assertEquals(new Integer(3), ret.getRow(0).get(1)); } } /* * $Log: NotClauseTest.java,v $ * Revision 1.1 2005/03/06 17:34:06 lheuer * Initial tolog import * * Revision 1.5 2004/06/14 20:10:33 kal_ahmed * Updated test code to work with new Predicate and Clause interfaces. * * Revision 1.4 2004/06/09 20:20:31 kal_ahmed * Major reworking of the predicate interfaces and internal implementation of VariableSet to reduce the use of HashMaps. * * Revision 1.3 2004/06/03 20:04:56 kal_ahmed * Completed initial package restructuring. * * Revision 1.2 2004/06/03 19:55:17 kal_ahmed * Created utils package to hold common utility classes for Tolog implementations. * * Revision 1.1 2004/05/30 22:08:25 kal_ahmed * Initial version of tolog 1.0 engine * */ --- NEW FILE: Increment.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/test/Increment.java,v 1.1 2005/03/06 17:34:06 lheuer Exp $ */ package org.tmapiutils.query.tolog.test; 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.predicates.PredicateBase; import org.tmapiutils.query.tolog.utils.VariableSet; import org.tmapi.core.TopicMap; /** * * @author Kal Ahmed (ka...@te...) */ public class Increment extends PredicateBase { static final ParameterInfo [] PARAMINFO = new ParameterInfo[] { new ParameterInfo(true, Integer.class), new ParameterInfo(true, Integer.class) }; /* (non-Javadoc) * @see org.tmapiutils.query.tolog.Predicate#matches(java.util.Map) */ public VariableSet matches(List params) throws TologProcessingException { Object o1 = params.get(0); Object o2 = params.get(1); VariableSet ret = new VariableSet(); initialiseResultsSet(ret); if ((o1 instanceof Variable) && !(o2 instanceof Variable)) { Variable var = (Variable)o1; if (o2 instanceof Integer) { Integer i = (Integer)o2; addResultsRow(ret, new Object[] {new Integer(i.intValue() - 1), i}); } } else if ((o2 instanceof Variable) && !(o1 instanceof Variable)) { Variable var = (Variable)o2; if (o1 instanceof Integer) { Integer i = (Integer)o1; addResultsRow(ret, new Object[] { i, new Integer(i.intValue() + 1)}); } } else if ((o1 instanceof Integer) && (o2 instanceof Integer)) { if (((Integer)o1).intValue() + 1 == ((Integer)o2).intValue()) { addResultsRow(ret, new Object[] {o1, o2}); } } return ret; } private VariableSet createVariableSet() { VariableSet ret = new VariableSet(); Iterator it = getParameters().iterator(); while (it.hasNext()) { Object o = it.next(); if (o instanceof Variable) { ret.addColumn(o); } } return ret; } /* (non-Javadoc) * @see org.tmapiutils.query.tolog.PredicateBase#getPredicateName() */ public String getPredicateName() { return "increment"; } /* (non-Javadoc) * @see org.tmapiutils.query.tolog.PredicateBase#getParamInfo() */ public ParameterInfo[] getParamInfo() { return PARAMINFO; } /* (non-Javadoc) * @see org.tmapiutils.query.tolog.parser.Predicate#initialise(org.tmapi.core.TopicMap) */ public void initialise(TopicMap tm) throws TologParserException { // No-op for this predicate } } /* * $Log: Increment.java,v $ * Revision 1.1 2005/03/06 17:34:06 lheuer * Initial tolog import * * Revision 1.6 2004/06/09 22:15:09 kal_ahmed * Fixed parser to disallow player:role pairs in predicates other than dynamic association predicates. Fixed initialisation of extension predicates. Added DirectInstanceOfPredicate extension to in-memory query evaluator. * * Revision 1.5 2004/06/09 20:20:31 kal_ahmed * Major reworking of the predicate interfaces and internal implementation of VariableSet to reduce the use of HashMaps. * * Revision 1.4 2004/06/07 20:31:59 kal_ahmed * Completed work on projection and sorting. Performed a bit more code reorganisation. Added DirectInstanceOfPredicate. * * Revision 1.3 2004/06/03 20:04:56 kal_ahmed * Completed initial package restructuring. * * Revision 1.2 2004/06/03 19:55:17 kal_ahmed * Created utils package to hold common utility classes for Tolog implementations. * * Revision 1.1 2004/05/30 22:08:25 kal_ahmed * Initial version of tolog 1.0 engine * */ --- NEW FILE: VariableSetTest.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/test/VariableSetTest.java,v 1.1 2005/03/06 17:34:06 lheuer Exp $ */ package org.tmapiutils.query.tolog.test; import java.util.List; import junit.framework.TestCase; import org.tmapiutils.query.tolog.parser.Variable; import org.tmapiutils.query.tolog.utils.VariableSet; /** * * @author Kal Ahmed (ka...@te...) */ public class VariableSetTest extends TestCase { /** * Constructor for VariableSetTest. * @param arg0 */ public VariableSetTest(String arg0) { super(arg0); } public static void main(String[] args) { junit.textui.TestRunner.run(VariableSetTest.class); } public void testAddMatchResults() throws Exception { VariableSet base = new VariableSet(); base.addColumn(new Variable("A")); base.addColumn(new Variable("B")); base.addColumn(new Variable("C")); VariableSet results = new VariableSet(); results.addColumn(new Variable("A")); results.addColumn(new Variable("B")); results.addRow(new Object[] { "A1", "B1" }); results.addRow(new Object[] { "A2", "B2" }); base.addMatchResults(base.getColumns(), results); assertEquals(2, base.getRows().size()); List row1 = base.getRow(0); assertEquals(3, row1.size()); assertEquals("A1", row1.get(0)); assertEquals("B1", row1.get(1)); assertEquals(new Variable("C"), row1.get(2)); } public void testProject() throws Exception { VariableSet vs = new VariableSet(); Variable a = new Variable("A"); Variable b = new Variable("B"); Variable c = new Variable("C"); vs.addColumn(a); vs.addColumn(b); vs.addColumn(c); vs.addRow(new Object[] {"A1", "B1", "C1"}); List l = vs.project(new Variable[] {a, b}, null); assertEquals(1, l.size()); List row = (List) l.get(0); assertEquals(2, row.size()); assertEquals("A1", row.get(0)); assertEquals("B1", row.get(1)); l = vs.project(new Variable[] {a}, c); assertEquals(1, l.size()); row = (List) l.get(0); assertEquals(2, row.size()); assertEquals("A1", row.get(0)); assertEquals(new Integer(1), row.get(1)); vs.addRow(new Object[] { "A1", "B2", "C1" }); l = vs.project(new Variable[] {a}, c); assertEquals(1, l.size()); row = (List) l.get(0); assertEquals(2, row.size()); assertEquals("A1", row.get(0)); assertEquals(new Integer(2), row.get(1)); } public void testAddVariableSet() throws Exception { VariableSet vs1 = new VariableSet(); vs1.addColumn(new Variable("A")); vs1.addColumn(new Variable("B")); vs1.addRow(new Object[] {"A1", "B1"}); VariableSet vs2 = new VariableSet(); vs2.addColumn(new Variable("B")); vs2.addColumn(new Variable("C")); vs2.addRow(new Object[] {"B2", "C2"}); vs1.add(vs2); assertEquals(3, vs1.getColumns().size()); assertEquals(2, vs1.getRows().size()); List row1 = vs1.getRow(0); assertNotNull(row1); assertEquals("A1", row1.get(0)); assertEquals("B1", row1.get(1)); assertEquals(new Variable("C"), row1.get(2)); List row2 = vs1.getRow(1); assertNotNull(row2); assertEquals(new Variable("A"), row2.get(0)); assertEquals("B2", row2.get(1)); assertEquals("C2", row2.get(2)); } } /* * $Log: VariableSetTest.java,v $ * Revision 1.1 2005/03/06 17:34:06 lheuer * Initial tolog import * * Revision 1.3 2004/06/09 20:20:31 kal_ahmed * Major reworking of the predicate interfaces and internal implementation of VariableSet to reduce the use of HashMaps. * * Revision 1.2 2004/06/03 19:55:17 kal_ahmed * Created utils package to hold common utility classes for Tolog implementations. * * Revision 1.1 2004/05/30 22:08:26 kal_ahmed * Initial version of tolog 1.0 engine * */ --- NEW FILE: MemoryQueryEvaluatorImplTest.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/test/MemoryQueryEvaluatorImplTest.java,v 1.1 2005/03/06 17:34:06 lheuer Exp $ */ package org.tmapiutils.query.tolog.test; import java.io.File; import java.io.FileInputStream; import java.util.Arrays; import java.util.Iterator; import java.util.List; import junit.framework.TestCase; import org.tm4j.net.Locator; import org.tmapiutils.query.tolog.TologResultsSet; import org.tmapiutils.query.tolog.QueryEvaluator; import org.tmapiutils.query.tolog.QueryEvaluatorFactory; import org.tmapiutils.query.tolog.TologProcessingException; import org.tmapi.core.Topic; import org.tmapi.core.TopicMap; import org.tmapi.core.TopicMapObject; import org.tmapi.core.TopicMapProvider; import org.tmapi.core.TopicMapProviderException; import org.tmapi.core.TopicMapProviderFactory; import org.tmapi.core.source.SerializedTopicMapSource; /** * @author Kal * * Describe MemoryQueryEvaluatorImplTest here. */ public class MemoryQueryEvaluatorImplTest extends TestCase { private File m_tologTestDir; private TopicMapProvider m_provider; private TestQuery[] TEST_QUERIES = new TestQuery[] { new TestQuery("blocks1", "blocks.ltm", "select * from restson($A:upper, $B:lower)?", 2, 3, new Object[][] { new Object[] {new TopicRef("redblock"), new TopicRef("blueblock") } }), new TestQuery("blocks2", "blocks.ltm", "select $INST from direct-instance-of($INST, block)?", 1, 4, new Object[][] { new Object[] { new TopicRef("redblock")}, new Object[] { new TopicRef("blueblock")}, new Object[] { new TopicRef("greenblock")}, new Object[] { new TopicRef("yellowblock")} }), new TestQuery("blocks3", "blocks.ltm", "select $BLOCK, $OTHER, $SHAPE from restson($OTHER:lower, $BLOCK:upper), has-shape($OTHER:block, $SHAPE:shape)?", 3, 3, new Object [][] { new Object[] { new TopicRef("redblock"), new TopicRef("blueblock"), new TopicRef("cylinder") }, new Object[] { new TopicRef("redblock"), new TopicRef("greenblock"), new TopicRef("rectangle") }, new Object[] { new TopicRef("yellowblock"), new TopicRef("redblock"), new TopicRef("rectangle") } }), }; /** * Constructor for MemoryQueryEvaluatorImplTest. * @param arg0 */ public MemoryQueryEvaluatorImplTest(String arg0) { super(arg0); m_tologTestDir = getTologTestDirectory(); try { m_provider = initialiseProvider(); } catch (TopicMapProviderException e) { throw new RuntimeException("Unable to initialise topic map provider.", e); } } /** * Locates the directory containing tologx package test * resources. The directory is located by looking for * a subdirectory 'tologx' in the test directory specified * by the System property 'testdir' * @return the File that represents the tologx test resource directory. * @throws RuntimeException if the System property 'testdir' is not specified, * or if the test directory or the tologx subdirectory could not be found. */ public File getTologTestDirectory() { String testdirName = System.getProperty("testdir"); if (testdirName == null) { throw new RuntimeException("No value for system property 'testdir'"); } File f = new File(testdirName); if (!(f.exists() && f.isDirectory())) { throw new RuntimeException("File '" + testdirName + "' does not exist or is not a directory."); } File ret = new File(f, "tologx"); if (!(ret.exists() && ret.isDirectory())) { throw new RuntimeException("Could not find subdirectory 'tologx' in test directory '" + f.getAbsolutePath() + "'."); } return ret; } public TopicMapProvider initialiseProvider() throws TopicMapProviderException { TopicMapProviderFactory tmpf = TopicMapProviderFactory.newInstance(); return tmpf.newTopicMapProvider(System.getProperties()); } public static void main(String[] args) { junit.textui.TestRunner.run(MemoryQueryEvaluatorImplTest.class); } public TopicMap getTopicMap(File tmFile, boolean forceReload) throws Exception { Locator tmLoc = m_provider.getLocatorFactory().createLocator("URI", tmFile.toURL().toString()); TopicMap tm = m_provider.getTopicMap(tmLoc); if (tm != null) { if (forceReload) { tm.destroy(); } else { return tm; } } SerializedTopicMapSource src = new SerializedTopicMapSource(tmFile); return m_provider.addTopicMap(src); } /* * @see TestCase#setUp() */ protected void setUp() throws Exception { super.setUp(); } //---------------------------------------------------- // Tests //---------------------------------------------------- public void testSimpleQueryWithProjection() throws Exception { TopicMap tm = getTopicMap(new File(m_tologTestDir, "blocks.ltm"), false); assertNotNull(tm); QueryEvaluator qe = QueryEvaluatorFactory.newQueryEvaluator(tm); TologResultsSet results = qe.execute("select $A, $B from restson($A:upper, $B:lower)?"); assertNotNull(results); assertEquals(2, results.getNumCols()); assertEquals(3, results.getNumRows()); Object[][] expectedResults = new Object [][] { new Object[] { tm.getObjectByID("redblock"), tm.getObjectByID("blueblock") } }; checkResultsSet("simpleQuery", results, 2, 3, expectedResults); } public void testQueries() throws Exception { for (int i = 0; i < TEST_QUERIES.length; i++) { // Load the topic map if necessary TopicMap tm = getTopicMap(new File(m_tologTestDir, TEST_QUERIES[i].tm), false); // Convert TopicRef objects in the expected results set into the referenced objects in the topic map for (int j = 0; j < TEST_QUERIES[i].expectedRows.length; j++) { Object[] expectedRow = TEST_QUERIES[i].expectedRows[j]; for (int k = 0; k < expectedRow.length; k++) { if (expectedRow[k] instanceof TopicRef) { expectedRow[k] = tm.getObjectByID(((TopicRef)expectedRow[k]).id); } } } QueryEvaluator qe = QueryEvaluatorFactory.newQueryEvaluator(tm); try { TologResultsSet rs = qe.execute(TEST_QUERIES[i].queryString); if (TEST_QUERIES[i].parseErrorExpected) { fail(TEST_QUERIES[i].name + ": Expected a TologParserException"); } if (TEST_QUERIES[i].processingErrorExpected) { fail(TEST_QUERIES[i].name + ": Expected a TologProcessingException"); } checkResultsSet(TEST_QUERIES[i].name, rs, TEST_QUERIES[i].resultsCols, TEST_QUERIES[i].resultsRows, TEST_QUERIES[i].expectedRows); } catch (TologProcessingException ex) { if (TEST_QUERIES[i].processingErrorExpected) return; } } } public void testInlineModule() throws Exception { TopicMap tm = getTopicMap(new File(m_tologTestDir, "blocks.ltm"), false); Topic greenblock = tm.getTopicByID("greenblock"); Topic blueblock = tm.getTopicByID("blueblock"); assertNotNull(tm); QueryEvaluator qe = QueryEvaluatorFactory.newQueryEvaluator(tm); qe.addRule("rests-on-both($A, $B, $C) :- restson($A:upper, $B:lower), restson($A:upper, $C:lower), $C /= $B ."); TologResultsSet results = qe.execute("rests-on-both(redblock, $BLOCK1, $BLOCK2)?"); assertEquals(2, results.getNumRows()); List row = results.getRow(0); assertTrue((row.get(0).equals(blueblock) && row.get(1).equals(greenblock)) || (row.get(0).equals(greenblock) && row.get(1).equals(blueblock))); row = results.getRow(1); assertTrue((row.get(0).equals(blueblock) && row.get(1).equals(greenblock)) || (row.get(0).equals(greenblock) && row.get(1).equals(blueblock))); } public void testExternalModule() throws Exception { TopicMap tm = getTopicMap(new File(m_tologTestDir, "blocks.ltm"), false); Topic greenblock = tm.getTopicByID("greenblock"); Topic blueblock = tm.getTopicByID("blueblock"); QueryEvaluator qe = QueryEvaluatorFactory.newQueryEvaluator(tm); qe.addRulesModule(new FileInputStream(new File(m_tologTestDir, "blocks.tl")), "blocks"); TologResultsSet results = qe.execute("select $BLOCK1, $BLOCK2 from blocks::rests-on-both(redblock, $BLOCK1, $BLOCK2)?"); assertEquals(2, results.getNumRows()); List row = results.getRow(0); assertTrue((row.get(0).equals(blueblock) && row.get(1).equals(greenblock)) || (row.get(0).equals(greenblock) && row.get(1).equals(blueblock))); row = results.getRow(1); assertTrue((row.get(0).equals(blueblock) && row.get(1).equals(greenblock)) || (row.get(0).equals(greenblock) && row.get(1).equals(blueblock))); } public void testRecursiveRules() throws Exception { TopicMap tm = getTopicMap(new File(m_tologTestDir, "family.ltm"), false); QueryEvaluator qe = QueryEvaluatorFactory.newQueryEvaluator(tm); qe.addRule("descendant-of($A, $B) :- { parent-of($B:parent, $A:child) | parent-of($A:child, $C:parent), descendant-of($C, $B) }."); TologResultsSet rs = qe.execute("descendant-of(bart, $WHO) ?"); assertEquals(3, rs.getNumRows()); Topic homer = tm.getTopicByID("homer"); Topic marge = tm.getTopicByID("marge"); Topic granpa = tm.getTopicByID("granpa"); for (int i =0 ; i <3; i++) { List row = rs.getRow(i); Topic t = (Topic)row.get(0); System.out.println(t.getID()); assertTrue(row.contains(homer) || row.contains(marge) || row.contains(granpa)); } } public void testNameAndOccurrence() throws Exception { TopicMap tm = getTopicMap(new File(m_tologTestDir, "blocks.ltm"), false); QueryEvaluator qe = QueryEvaluatorFactory.newQueryEvaluator(tm); TologResultsSet rs = qe.execute("select $A, $D, $E from topic-name($A, $B), occurrence($A, $C), value($B, $D), value($C, $E)?"); for (int i = 0; i < rs.getNumRows(); i++) { System.out.println(dumpRow(rs.getRow(i))); } } public void testReplacement() throws Exception { TopicMap tm = getTopicMap(new File(m_tologTestDir, "blocks.ltm"), false); QueryEvaluator qe = QueryEvaluatorFactory.newQueryEvaluator(tm); TologResultsSet rst = qe.execute("select $A from restson($A:upper, %1:lower)?", new Object[] { tm.getTopicByID("redblock")}); assertEquals(1, rst.getNumRows()); assertEquals(tm.getTopicByID("yellowblock"), rst.getRow(0).get(0)); } private void checkResultsSet(String testName, TologResultsSet results, int expectedColSize, int expectedRowSize, Object[][]expectedRows) { assertEquals(testName + ": Unexpected results set width.", expectedColSize, results.getNumCols()); assertEquals(testName + ": Unexpected results set length.", expectedRowSize, results.getNumRows()); for (int i = 0; i < expectedRows.length; i++) { List expectedRow = Arrays.asList(expectedRows[i]); boolean gotMatch = false; for (int j = 0; (!gotMatch) && (j < results.getNumRows()); j++) { gotMatch = expectedRow.equals(results.getRow(j)); } assertTrue(testName + ": Expected to find a match for the row "+ dumpRow(expectedRow), gotMatch); } } private String dumpRow(List row) { StringBuffer ret = new StringBuffer(); ret.append("["); Iterator it = row.iterator(); while (it.hasNext()) { Object o = it.next(); if (o instanceof TopicMapObject) { ret.append(((TopicMapObject)o).getID()); } else { ret.append(o.toString()); } if (it.hasNext()) ret.append(", "); } ret.append("]"); return ret.toString(); } class TestQuery { String name; String tm; String queryString; boolean parseErrorExpected; boolean processingErrorExpected; int resultsCols; int resultsRows; Object [][] expectedRows; public TestQuery(String name, String tm, String queryString, boolean parseErrorExpected, boolean processingErrorExpected) { this.name = name; this.tm = tm; this.queryString = queryString; this.parseErrorExpected = parseErrorExpected; this.processingErrorExpected = processingErrorExpected; } public TestQuery(String name, String tm, String queryString, int resultsCols, int resultsRows, Object[][]expectedRows) { this.name = name; this.tm = tm; this.queryString = queryString; this.resultsCols = resultsCols; this.resultsRows = resultsRows; this.expectedRows = expectedRows; } } class TopicRef { String id; TopicRef(String id) { this.id = id; } } } /* * $Log: MemoryQueryEvaluatorImplTest.java,v $ * Revision 1.1 2005/03/06 17:34:06 lheuer * Initial tolog import * * Revision 1.11 2004/11/02 16:03:39 kal_ahmed * Fixed reported bug with processing external tolog modules. * * Revision 1.10 2004/06/20 14:12:31 kal_ahmed * Copied TologRsultsSet interface and TologFragmentBuilder implementation from org.tm4j.tolog to this package. * * Revision 1.9 2004/06/16 21:21:44 kal_ahmed * Tolog queries may now contain replaceable references specified in an Object array parameter to the QueryEvaluator at evaluation time. * * Revision 1.8 2004/06/14 21:33:07 kal_ahmed * Fixed query evaluation when multiple predicates introduce new variables. * * Revision 1.7 2004/06/13 19:58:12 kal_ahmed * Fixed testRecursiveRules() query. Reinstated disabled tests. * * Revision 1.6 2004/06/13 19:44:31 kal_ahmed * Added a fix and test for handling recursive rules definitions. * * Revision 1.5 2004/06/13 17:18:00 kal_ahmed * Added registration of builtin predicates. Fixed rule expansion code to handle player/role pairs correctly. * * Revision 1.4 2004/06/09 22:15:09 kal_ahmed * Fixed parser to disallow player:role pairs in predicates other than dynamic association predicates. Fixed initialisation of extension predicates. Added DirectInstanceOfPredicate extension to in-memory query evaluator. * * Revision 1.3 2004/06/09 21:12:19 kal_ahmed * Added standard source file header and footer. * */ --- NEW FILE: TologParserTest.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/test/TologParserTest.java,v 1.1 2005/03/06 17:34:06 lheuer Exp $ */ package org.tmapiutils.query.tolog.test; import java.io.StringReader; import java.util.HashMap; import java.util.Map; import org.tmapiutils.query.tolog.parser.ClauseList; 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.TopicNamePredicate; import org.tmapiutils.query.tolog.predicates.TopicPredicate; 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.Association; import org.tmapi.core.AssociationRole; import org.tmapi.core.Topic; import org.tmapi.core.TopicMap; /** * * @author Kal Ahmed (ka...@te...) */ public class TologParserTest extends TologParserTestBase { private String [][] m_parserTest = { {"contains( $A : container, $B : containee ) ?", "select * from contains($A:container, $B:containee)?"}, {"contains( $B : container, uk : containee )?", "select * from contains($B:container, uk:containee)?"}, {"not(contains(europe : container, $B : containee))?", "select * from not(contains(europe:container, $B:containee))?"}, { "{ contains(europe:container, $B:containee) | contains(asia:container, $B:containee) }?", "select * from { contains(europe:container, $B:containee) | contains(asia:container, $B:containee) }?"}, { "contains($A : container, $B : containee), contains($A: container, $C:containee), $B /= $C ?", "select * from contains($A:container, $B:containee), contains($A:container, $C:containee), $B /= $C?" }, { "select $A, $B from contains($A:container, $B:containee)?", "select $A, $B from contains($A:container, $B:containee)?" }, { "select $A from contains(europe:container, $A:containee) order by $A asc ?", "select $A from contains(europe:container, $A:containee) order by $A asc ?" }, { "select $A from contains(europe:container, $A:containee) limit 10 offset 5 ?", "select $A from contains(europe:container, $A:containee) limit 10 offset 5 ?" }, { "select $A from contains(%1:container, %2:containee)?", "select $A from contains(%1:container, %2:containee)?", }, { "select $A from %1(europe:container, $A:containee)?", "select $A from %1(europe:container, $A:containee)?" }, { "select $A from contains(europe:%1, $A:containee)?", "select $A from contains(europe:%1, $A:containee)?" }, { "select $ASSOC from $ASSOC(europe, france) ?", "select $ASSOC from $ASSOC(europe, france)?" } }; private final String [][] m_rulesTest = { { "nestedin($A, $B) :- { contains($B, $A) | contains($C, $A), nestedin($C, $B) }.", "nestedin($A, $B) :- { contains($B, $A) | contains($C, $A), nestedin($C, $B) }." }, { "nestedin($A, $B) :- contains($C, $A), contains($B, $C).", "nestedin($A, $B) :- contains($C, $A), contains($B, $C)." } /* { "daynumberOfEmail($A,$C) :- {mail-time-assoc($A:time-of,$B:message-time),day-time-assoc($B:time,$C:day)}.", "daynumberOfEmail($A,$C) :- {mail-time-assoc($A:time-of,$B:message-time),day-time-assoc($B:time,$C:day)}.", } */ }; private final String [][] m_parserTest2 = { { "select $ASSOC, $ROLE1, $ROLE2 from " + " association-role($ASSOC, $ROLE1)," + " role-player($ROLE1, AT1)," + " association-role($ASSOC, $ROLE2)," + " role-player($ROLE2, AT2)," + " type($ASSOC, activity_responsibility)?", "select $ASSOC, $ROLE1, $ROLE2 from " + " association-role($ASSOC, $ROLE1)," + " role-player($ROLE1, AT1)," + " association-role($ASSOC, $ROLE2)," + " role-player($ROLE2, AT2)," + " type($ASSOC, activity_responsibility)?", }, { "select $ASSOC, $ROLE1, $ROLE2 from " + " association-role($ASSOC, $ROLE1)," + " role-player($ROLE1, AT1)," + " association-role($ASSOC, $ROLE2)," + " role-player($ROLE2, AT2)?", "select $ASSOC, $ROLE1, $ROLE2 from " + " association-role($ASSOC, $ROLE1)," + " role-player($ROLE1, AT1)," + " association-role($ASSOC, $ROLE2)," + " role-player($ROLE2, AT2)?" } }; private Map m_predicatesByName; /** * Constructor for TologParserTest. * @param arg0 */ public TologParserTest(String arg0) { super(arg0); } public static void main(String[] args) { junit.textui.TestRunner.run(TologParserTest.class); } public void testParse1() throws Exception { String queryString = "contains($A:container, $B:containee)?"; TologParser p = new TologParser(new TologLexer(new StringReader(queryString))); p.setTopicMap(m_tm); TologQuery q = p.query(); assertNotNull(q); ClauseList rootClauseList = q.getRootClauseList(); assertEquals(1, rootClauseList.size()); assertEquals("select * from contains($A:container, $B:containee)?", q.toString()); } public void testParser() throws Exception { for (int i =0; i < m_parserTest.length; i++) { TologParser p = new TologParser(new TologLexer(new StringReader(m_parserTest[i][0]))); p.setTopicMap(m_tm); TologQuery q = p.query(); assertNotNull(q); System.out.println(q.toString()); assertEquals("Comparison failure for input " + m_parserTest[i][0], m_parserTest[i][1], q.toString()); } } public void testParser2() throws Exception { for (int i = 0; i < m_parserTest2.length; i++) { m_predicatesByName = new HashMap(); initialisePredicates(); TologParser p = new TologParser(new TologLexer(new StringReader(m_parserTest2[i][0]))); p.setTopicMap(m_tm2); p.setPredicates(m_predicatesByName); TologQuery q = p.query(); a... [truncated message content] |
Update of /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26709/src/org/tmapiutils/query/tolog/predicates/test Added 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: Initial tolog import --- NEW FILE: ResourcePredicateTest.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test/ResourcePredicateTest.java,v 1.1 2005/03/06 17:33:23 lheuer Exp $ */ package org.tmapiutils.query.tolog.predicates.test; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.tm4j.net.Locator; import org.tmapiutils.query.tolog.parser.Variable; import org.tmapiutils.query.tolog.predicates.ResourcePredicate; import org.tmapiutils.query.tolog.utils.VariableSet; import org.tmapi.core.Occurrence; /** * * @author Kal Ahmed (ka...@te...) */ 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; } /* (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 = m_tm.getTopicByID("techquila").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 = m_tm.getTopicByID("tm4j").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 l = m_tm.getLocatorFactory().createLocator("URI", "http://www.techquila.com/"); params.add(a); params.add(l); 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 = m_tm.getTopicByID("techquila").getOccurrences().iterator(); while (it.hasNext()) { Occurrence o = (Occurrence)it.next(); if (o.getResource().equals(l)) { 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 l = m_tm.getLocatorFactory().createLocator("URI", "http://www.techquila.com/"); Occurrence o = null; Iterator it = m_tm.getTopicByID("techquila").getOccurrences().iterator(); while (it.hasNext()) { o = (Occurrence)it.next(); if (o.getResource().equals(l)) { 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(l)); } // TODO: Implement tests for closed matches. } /* * $Log: ResourcePredicateTest.java,v $ * Revision 1.1 2005/03/06 17:33:23 lheuer * Initial tolog import * * Revision 1.1 2004/07/27 10:15:57 kal_ahmed * Initial version * */ --- NEW FILE: PredicateTestBase.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test/PredicateTestBase.java,v 1.1 2005/03/06 17:33:23 lheuer Exp $ */ package org.tmapiutils.query.tolog.predicates.test; import java.io.StringReader; import junit.framework.TestCase; import org.tm4j.net.Locator; import org.tmapiutils.query.tolog.parser.Predicate; import org.tmapiutils.query.tolog.utils.TologContext; import org.tmapi.core.TopicMap; import org.tmapi.core.TopicMapProvider; import org.tmapi.core.TopicMapProviderFactory; import org.tmapi.core.memory.TopicMapProviderFactoryImpl; import org.tmapi.core.source.SerializedTopicMapSource; import org.tmapi.core.utils.LTMBuilder; import org.tmapi.core.utils.TopicMapBuilder; /** * @author Kal * * Describe PredicateTestBase here. */ public abstract class PredicateTestBase extends TestCase { protected Predicate m_predicate; protected TopicMap m_tm; protected TopicMapProvider m_provider; protected TologContext m_context; public abstract String getTestMap(); public abstract Class getPredicateClass(); public PredicateTestBase(String name) { super(name); } public TopicMapBuilder getBuilder() { return new LTMBuilder(); } public 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(getTestMap()), loc, getBuilder()); m_tm = m_provider.addTopicMap(src); m_predicate = (Predicate) getPredicateClass().newInstance(); m_predicate.initialise(m_tm); m_context = new TologContext(); } } /* * $Log: PredicateTestBase.java,v $ * Revision 1.1 2005/03/06 17:33:23 lheuer * Initial tolog import * * Revision 1.4 2004/06/14 20:09:46 kal_ahmed * Updated test code to work with new Predicate interface. * * Revision 1.3 2004/06/13 11:30:26 kal_ahmed * Initial implementation of value-like predicate. * * Revision 1.2 2004/06/10 17:09:35 kal_ahmed * Added reifies and instance-of predicates. * */ --- NEW FILE: TopicMapPredicateTest.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test/TopicMapPredicateTest.java,v 1.1 2005/03/06 17:33:23 lheuer Exp $ */ 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; /** * * @author Kal Ahmed (ka...@te...) */ 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]"; } /* (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, m_tm.getTopicByID("hello-world")); out = m_predicate.matches(params, m_context); assertNotNull(out); assertEquals(0, out.getRows().size()); } } /* * $Log: TopicMapPredicateTest.java,v $ * Revision 1.1 2005/03/06 17:33:23 lheuer * Initial tolog import * * Revision 1.2 2004/06/14 20:09:46 kal_ahmed * Updated test code to work with new Predicate interface. * * Revision 1.1 2004/06/13 10:32:29 kal_ahmed * Initial implementation of topicmap() predicate. * */ --- NEW FILE: ReifiesPredicateTest.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test/ReifiesPredicateTest.java,v 1.1 2005/03/06 17:33:23 lheuer Exp $ */ 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; import org.tmapi.core.utils.TopicMapBuilder; import org.tmapi.core.utils.XTMBuilder; /** * @author Kal * * Describe ReifiesPredicateTest here. */ 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(); } /* (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(m_tm.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(m_tm.getObjectByID("fredemp"))); } public void testMatchReified() throws Exception { ArrayList params = new ArrayList(); Variable a = new Variable("A"); params.add(m_tm.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(m_tm.getObjectByID("assoc1"))); } 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(m_tm.getObjectByID("fredemp"))); assertTrue(out.getRow(0).get(1).equals(m_tm.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, m_tm.getObjectByID("fredemp")); params.set(1, m_tm.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, m_tm.getObjectByID("fredemp")); params.set(1, m_tm.getObjectByID("m1")); out = m_predicate.matches(params, m_context); assertNotNull(out); assertEquals(2, out.getColumns().size()); assertEquals(0, out.getRows().size()); } } /* * $Log: ReifiesPredicateTest.java,v $ * Revision 1.1 2005/03/06 17:33:23 lheuer * Initial tolog import * * Revision 1.2 2004/06/14 20:09:46 kal_ahmed * Updated test code to work with new Predicate interface. * * Revision 1.1 2004/06/10 17:09:35 kal_ahmed * Added reifies and instance-of predicates. * */ --- NEW FILE: AssociationRolePredicateTest.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test/AssociationRolePredicateTest.java,v 1.1 2005/03/06 17:33:23 lheuer Exp $ */ 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; import org.tmapi.core.Association; import org.tmapi.core.AssociationRole; import org.tmapi.core.Topic; /** * @author Kal * * Describe AssociationRolePredicateTest here. */ 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"; } /* (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"); AssociationRole m = (AssociationRole) m_tm.getTopicByID("fred").getRolesPlayed().iterator().next(); params.add(a); params.add(m); 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(m.getParent(), out.getRow(0).get(0)); } public void testMatchRoles() throws Exception { ArrayList params = new ArrayList(); Association assoc = ((AssociationRole)m_tm.getTopicByID("barney").getRolesPlayed().iterator().next()).getParent(); 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)).getParent()); assertEquals(assoc, ((AssociationRole)out.getRow(1).get(0)).getParent()); } 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)).getParent()); } } 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 = m_tm.getTopicByID("fred"); AssociationRole m = (AssociationRole) fred.getRolesPlayed().iterator().next(); Association assoc = m.getParent(); params.set(0, assoc); params.set(1, m); VariableSet out = m_predicate.matches(params, m_context); assertNotNull(out); assertEquals(2, out.getColumns().size()); assertEquals(1, out.getRows().size()); Topic barney = m_tm.getTopicByID("barney"); AssociationRole m2 = (AssociationRole)barney.getRolesPlayed().iterator().next(); params.set(1, m2); out = m_predicate.matches(params, m_context); assertNotNull(out); assertEquals(2, out.getColumns().size()); assertEquals(0, out.getRows().size()); } } /* * $Log: AssociationRolePredicateTest.java,v $ * Revision 1.1 2005/03/06 17:33:23 lheuer * Initial tolog import * * Revision 1.2 2004/06/14 20:09:46 kal_ahmed * Updated test code to work with new Predicate interface. * * Revision 1.1 2004/06/11 08:29:29 kal_ahmed * Added association and association-role predicates. * */ --- NEW FILE: DirectInstanceOfPredicateTest.java --- /* * Created on 10-Jun-2004 * @author Kal */ package org.tmapiutils.query.tolog.predicates.test; import java.io.StringReader; import java.util.ArrayList; import java.util.List; import org.tm4j.net.Locator; import org.tmapiutils.query.tolog.parser.Predicate; import org.tmapiutils.query.tolog.parser.Variable; import org.tmapiutils.query.tolog.predicates.DirectInstanceOfPredicate; import org.tmapiutils.query.tolog.utils.TologContext; import org.tmapiutils.query.tolog.utils.VariableSet; import org.tmapi.core.TopicMap; import org.tmapi.core.TopicMapProvider; import org.tmapi.core.TopicMapProviderFactory; import org.tmapi.core.memory.TopicMapProviderFactoryImpl; import org.tmapi.core.source.SerializedTopicMapSource; import org.tmapi.core.utils.LTMBuilder; import junit.framework.TestCase; /** * @author Kal * * Describe DirectInstanceOfPredicateTest here. */ public class DirectInstanceOfPredicateTest extends TestCase { private Predicate m_predicate; private TopicMap m_tm; private TopicMapProvider m_provider; private TologContext m_context; /** * Constructor for DirectInstanceOfPredicateTest. * @param arg0 */ public DirectInstanceOfPredicateTest(String arg0) { super(arg0); } public static void main(String[] args) { junit.textui.TestRunner.run(DirectInstanceOfPredicateTest.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(5, out.getRows().size()); assertTrue(out.getColumn(a).contains(m_tm.getObjectByID("digestive"))); assertTrue(out.getColumn(a).contains(m_tm.getObjectByID("battenburg"))); assertTrue(out.getColumn(a).contains(m_tm.getObjectByID("custardcream"))); assertTrue(out.getColumn(a).contains(m_tm.getObjectByID("jaffacake"))); assertTrue(out.getColumn(b).contains(m_tm.getObjectByID("biscuit"))); assertTrue(out.getColumn(b).contains(m_tm.getObjectByID("cake"))); } public void testClassMatch() throws Exception { List params = new ArrayList(); Variable a = new Variable("A"); params.add(a); params.add(m_tm.getTopicByID("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(m_tm.getObjectByID("battenburg"))); assertTrue(out.getColumn(a).contains(m_tm.getObjectByID("jaffacake"))); } public void testInstanceMatch() throws Exception { List params = new ArrayList(); Variable a = new Variable("A"); params.add(m_tm.getTopicByID("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(m_tm.getObjectByID("cake"))); assertTrue(out.getColumn(a).contains(m_tm.getObjectByID("biscuit"))); } public void testClosedMatch() throws Exception { List params = new ArrayList(); Variable a = new Variable("A"); params.add(a); params.add(m_tm.getTopicByID("cake")); m_predicate.setParameters(params); params.set(0, m_tm.getTopicByID("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(m_tm.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(); } private static final String TESTMAP = "[digestive:biscuit]\n" + "[battenburg:cake]\n" + "[jaffacake:cake]\n" + "[jaffacake:biscuit]\n" + "[custardcream:biscuit]\n"; } --- NEW FILE: BaseLocatorPredicateTest.java --- /* * Created on 11-Jun-2004 * @author Kal */ package org.tmapiutils.query.tolog.predicates.test; import java.util.ArrayList; import org.tmapiutils.query.tolog.parser.Variable; import org.tmapiutils.query.tolog.predicates.BaseLocatorPredicate; import org.tmapiutils.query.tolog.utils.VariableSet; /** * @author Kal * * Describe BaseLocatorPredicateTest here. */ public class BaseLocatorPredicateTest extends PredicateTestBase { /** * @param name */ public BaseLocatorPredicateTest(String name) { super(name); } /* (non-Javadoc) * @see org.tmapiutils.query.tolog.predicates.test.PredicateTestBase#getTestMap() */ public String getTestMap() { return "[test]"; } /* (non-Javadoc) * @see org.tmapiutils.query.tolog.predicates.test.PredicateTestBase#getPredicateClass() */ public Class getPredicateClass() { return BaseLocatorPredicate.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.getColumns().size()); assertEquals(1, out.getRows().size()); assertEquals(m_tm.getBaseLocator(), 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.getBaseLocator()); VariableSet out = m_predicate.matches(params, m_context); assertNotNull(out); assertEquals(1, out.getColumns().size()); assertEquals(1, out.getRows().size()); assertEquals(m_tm.getBaseLocator(), out.getRow(0).get(0)); params.set(0, m_tm.getBaseLocator().resolveRelative("foobar")); out = m_predicate.matches(params, m_context); assertNotNull(out); assertEquals(1, out.getColumns().size()); assertEquals(0, out.getRows().size()); } } --- NEW FILE: DynamicAssociationPredicateTest.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test/DynamicAssociationPredicateTest.java,v 1.1 2005/03/06 17:33:23 lheuer Exp $ */ package org.tmapiutils.query.tolog.predicates.test; import java.io.StringReader; import java.util.ArrayList; import java.util.List; import junit.framework.TestCase; import org.apache.log4j.BasicConfigurator; import org.tm4j.net.Locator; 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; import org.tmapi.core.TopicMap; import org.tmapi.core.TopicMapProvider; import org.tmapi.core.TopicMapProviderFactory; import org.tmapi.core.memory.TopicMapProviderFactoryImpl; import org.tmapi.core.source.SerializedTopicMapSource; import org.tmapi.core.utils.LTMBuilder; /** * * @author Kal Ahmed (ka...@te...) */ public class DynamicAssociationPredicateTest extends TestCase { private TopicMap m_tm; private TopicMapProvider m_provider; private TologContext m_context; /** * Constructor for AssociationPredicateTest. * @param arg0 */ public DynamicAssociationPredicateTest(String arg0) { super(arg0); BasicConfigurator.configure(); } public static void main(String[] args) { junit.textui.TestRunner.run(DynamicAssociationPredicateTest.class); BasicConfigurator.configure(); } public void testSimpleMatch() throws Exception { ClauseList c = new ClauseList(); DynamicAssociationPredicate p = new DynamicAssociationPredicate(); ArrayList params = new ArrayList(); params.add(m_tm.getTopicByID("worksfor")); params.add(new PlayerRoleVarPair(m_tm.getTopicByID("kal"), m_tm.getTopicByID("employee"))); params.add(new PlayerRoleVarPair(new Variable("A"), m_tm.getTopicByID("employer"))); p.setParameters(params); c.addPredicate(p); VariableSet varsIn = new VariableSet(); varsIn.addColumn(new Variable("A")); VariableSet varsOut = c.execute(varsIn, m_context); assertEquals(1, varsOut.size()); List r = varsOut.getRow(0); assertNotNull(r); assertEquals(r.size(), 1); assertEquals(m_tm.getTopicByID("techquila"), r.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.getTopicByID("worksfor")); params.add(new PlayerRoleVarPair(new Variable("PERSON"), m_tm.getTopicByID("employee"))); params.add(new PlayerRoleVarPair(new Variable("COMPANY"), m_tm.getTopicByID("employer"))); p.setParameters(params); c.addPredicate(p); VariableSet varsIn = new VariableSet(); varsIn.addColumn(new Variable("PERSON")); varsIn.addColumn(new Variable("COMPANY")); VariableSet varsOut = c.execute(varsIn, m_context); 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(m_tm.getTopicByID("kal")) || row.get(0).equals(m_tm.getTopicByID("fred"))); assertTrue( row.get(1).equals(m_tm.getTopicByID("techquila")) || row.get(1).equals(m_tm.getTopicByID("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"), m_tm.getTopicByID("employee"))); params.add(new PlayerRoleVarPair(new Variable("COMPANY"), m_tm.getTopicByID("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")); VariableSet varsOut = c.execute(varsIn, m_context); assertEquals(2, varsOut.size()); for (int i = 0; i < 2; i++) { List row = varsOut.getRow(i); assertNotNull(row); assertEquals(row.size(), 3); assertEquals(m_tm.getTopicByID("worksfor"), row.get(0)); assertTrue( row.get(1).equals(m_tm.getTopicByID("kal")) || row.get(1).equals(m_tm.getTopicByID("fred"))); assertTrue( row.get(2).equals(m_tm.getTopicByID("techquila")) || row.get(2).equals(m_tm.getTopicByID("bigcorp"))); } } /* (non-Javadoc) * @see junit.framework.TestCase#setUp() */ 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); assertNotNull(m_tm.getTopicByID("worksfor")); m_context = new TologContext(); } private static final String TESTMAP ="worksfor(kal:employee, techquila:employer)\n" + "worksfor(fred:employee, bigcorp:employer)\n"; } /* * $Log: DynamicAssociationPredicateTest.java,v $ * Revision 1.1 2005/03/06 17:33:23 lheuer * Initial tolog import * * Revision 1.3 2004/06/14 20:09:46 kal_ahmed * Updated test code to work with new Predicate interface. * * Revision 1.2 2004/06/09 20:20:30 kal_ahmed * Major reworking of the predicate interfaces and internal implementation of VariableSet to reduce the use of HashMaps. * * Revision 1.1 2004/06/07 20:42:24 kal_ahmed * Added infrastructure for backend-specific implementations and start of a default in-memory implementation. * * Revision 1.3 2004/06/03 20:04:56 kal_ahmed * Completed initial package restructuring. * * Revision 1.2 2004/06/03 19:55:17 kal_ahmed * Created utils package to hold common utility classes for Tolog implementations. * * Revision 1.1 2004/05/30 22:08:25 kal_ahmed * Initial version of tolog 1.0 engine * */ --- NEW FILE: VariantPredicateTest.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test/VariantPredicateTest.java,v 1.1 2005/03/06 17:33:24 lheuer Exp $ */ package org.tmapiutils.query.tolog.predicates.test; import java.util.ArrayList; import org.tmapiutils.query.tolog.parser.Variable; import org.tmapiutils.query.tolog.predicates.VariantPredicate; import org.tmapiutils.query.tolog.utils.VariableSet; import org.tmapi.core.TopicName; import org.tmapi.core.Variant; /** * * @author Kal Ahmed (ka...@te...) */ public class VariantPredicateTest extends PredicateTestBase { /** * @param name */ public VariantPredicateTest(String name) { super(name); } /* (non-Javadoc) * @see org.tmapiutils.query.tolog.predicates.test.PredicateTestBase#getTestMap() */ public String getTestMap() { return "[fred = \"Fred Flinstone\";\"Flintstone, F.\"]\n" + "[barney = \"Barney Rubble\";\"Rubble, B.\"]"; } /* (non-Javadoc) * @see org.tmapiutils.query.tolog.predicates.test.PredicateTestBase#getPredicateClass() */ public Class getPredicateClass() { return VariantPredicate.class; } public void testGetVariants() 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); TopicName fredName = (TopicName) m_tm.getTopicByID("fred").getTopicNames().iterator().next(); params.set(0, fredName); VariableSet out = m_predicate.matches(params, m_context); assertNotNull(out); assertEquals(1, out.getRows().size()); assertEquals(fredName.getVariants().iterator().next(), out.getRow(0).get(1)); } public void testGetTopicName() 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); TopicName fredName = (TopicName) m_tm.getTopicByID("fred").getTopicNames().iterator().next(); Variant fredVar = (Variant) fredName.getVariants().iterator().next(); params.set(1, fredVar); VariableSet out = m_predicate.matches(params, m_context); assertNotNull(out); assertEquals(1, out.getRows().size()); assertEquals(fredName, out.getRow(0).get(0)); } 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); TopicName fredName = (TopicName) m_tm.getTopicByID("fred").getTopicNames().iterator().next(); Variant fredVar = (Variant) fredName.getVariants().iterator().next(); params.set(0, fredName); params.set(1, fredVar); VariableSet out = m_predicate.matches(params, m_context); assertNotNull(out); assertEquals(1, out.getRows().size()); assertEquals(fredName, out.getRow(0).get(0)); assertEquals(fredVar, out.getRow(0).get(1)); } 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.getRows().size()); } } /* * $Log: VariantPredicateTest.java,v $ * Revision 1.1 2005/03/06 17:33:24 lheuer * Initial tolog import * * Revision 1.2 2004/06/14 20:09:46 kal_ahmed * Updated test code to work with new Predicate interface. * * Revision 1.1 2004/06/13 10:56:32 kal_ahmed * Initial implementation of variant() predicate. * */ --- NEW FILE: ValuePredicateTest.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test/ValuePredicateTest.java,v 1.1 2005/03/06 17:33:23 lheuer Exp $ */ 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.ValuePredicate; import org.tmapiutils.query.tolog.utils.VariableSet; import org.tmapi.core.TopicName; import org.tmapi.core.DataObject; import org.tmapi.core.Occurrence; /** * * @author Kal Ahmed (ka...@te...) */ public class ValuePredicateTest extends PredicateTestBase { /** * @param name */ public ValuePredicateTest(String name) { super(name); } /* (non-Javadoc) * @see org.tmapiutils.query.tolog.predicates.test.PredicateTestBase#getTestMap() */ public String getTestMap() { return "[bond = \"James Bond\";\"bond, james\";\"James Bond\"\n" + " = \"007\" / hmg]" + "{bond, favourite-drink, [[\"Vodka martini. Shaken not stirred\"]]}"; } /* (non-Javadoc) * @see org.tmapiutils.query.tolog.predicates.test.PredicateTestBase#getPredicateClass() */ public Class getPredicateClass() { return ValuePredicate.class; } public void testMatchOnValue() throws Exception { ArrayList params = new ArrayList(); Variable a = new Variable("A"); params.add(a); params.add("James Bond"); m_predicate.setParameters(params); VariableSet out = m_predicate.matches(params, m_context); assertNotNull(out); assertEquals(1, out.getColumns().size()); // TODO: This should be 2 when indexing of Variant names is supported. assertEquals(1, out.getRows().size()); Iterator it = out.getColumn(a).iterator(); while (it.hasNext()) { Object o = it.next(); if (o instanceof TopicName) { assertEquals("James Bond", ((TopicName)o).getValue()); } else if (o instanceof Occurrence) { assertEquals("James Bond", ((Occurrence)o).getValue()); } } } public void testMatchOnObject() 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); TopicName bn = (TopicName)m_tm.getTopicByID("bond").getTopicNames().iterator().next(); params.set(0, bn); VariableSet out = m_predicate.matches(params, m_context); assertNotNull(out); assertEquals(2, out.getColumns().size()); assertEquals(1, out.getRows().size()); Iterator it = out.getColumn(b).iterator(); while (it.hasNext()) { Object o = it.next(); assertTrue(o instanceof String); assertEquals(bn.getValue(), o); } Occurrence o = (Occurrence)m_tm.getTopicByID("bond").getOccurrences().iterator().next(); assertNotNull(o.getValue()); params.set(0, o); out = m_predicate.matches(params, m_context); assertNotNull(out); assertEquals(2, out.getColumns().size()); assertEquals(1, out.getRows().size()); assertEquals(o.getValue(), out.getRow(0).get(1)); } 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); TopicName bn = (TopicName)m_tm.getTopicByID("bond").getTopicNames().iterator().next(); params.set(0, bn); params.set(1, bn.getValue()); VariableSet out = m_predicate.matches(params, m_context); assertNotNull(out); assertEquals(2, out.getColumns().size()); assertEquals(1, out.getRows().size()); Iterator it = out.getColumn(b).iterator(); while (it.hasNext()) { Object o = it.next(); assertTrue(o instanceof String); assertEquals(bn.getValue(), o); } params.set(1, "NOMATCH"); out = m_predicate.matches(params, m_context); assertNotNull(out); assertEquals(2, out.getColumns().size()); assertEquals(0, out.getRows().size()); Occurrence o = (Occurrence)m_tm.getTopicByID("bond").getOccurrences().iterator().next(); assertNotNull(o.getValue()); params.set(0, o); params.set(1, o.getValue()); out = m_predicate.matches(params, m_context); assertNotNull(out); assertEquals(2, out.getColumns().size()); assertEquals(1, out.getRows().size()); assertEquals(o.getValue(), out.getRow(0).get(1)); params.set(1, "NOMATCH"); out = m_predicate.matches(params, m_context); assertNotNull(out); assertEquals(2, out.getColumns().size()); assertEquals(0, out.getRows().size()); } 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(5, out.getRows().size()); Iterator it = out.getRows().iterator(); while (it.hasNext()) { List row = (List)it.next(); Object o = row.get(0); String v = (String)row.get(1); if (o instanceof TopicName) { assertEquals(v, ((TopicName)o).getValue()); } else if (o instanceof DataObject) { assertEquals(v, ((DataObject)o).getValue()); } } } } /* * $Log: ValuePredicateTest.java,v $ * Revision 1.1 2005/03/06 17:33:23 lheuer * Initial tolog import * * Revision 1.2 2004/06/14 20:09:46 kal_ahmed * Updated test code to work with new Predicate interface. * * Revision 1.1 2004/06/13 09:06:43 kal_ahmed * Initial version of value() predicate. * */ --- NEW FILE: TopicNameTest.java --- /* * Created on 14-Jun-2004 * @author Kal */ package org.tmapiutils.query.tolog.predicates.test; import java.util.ArrayList; import org.tmapiutils.query.tolog.parser.Variable; import org.tmapiutils.query.tolog.predicates.TopicNamePredicate; import org.tmapiutils.query.tolog.utils.TologContext; import org.tmapiutils.query.tolog.utils.VariableSet; import org.tmapi.core.TopicName; import org.tmapi.core.Topic; /** * @author Kal * * Describe TopicNameTest here. */ public class TopicNameTest extends PredicateTestBase { /** * @param name */ public TopicNameTest(String name) { super(name); } /* (non-Javadoc) * @see org.tmapiutils.query.tolog.predicates.test.PredicateTestBase#getTestMap() */ public String getTestMap() { return "[topic1 = \"Topic1\"]\n" + "[topic2 = \"Topic2\"]\n" + "[topic3 = \"Topic3\";\"topic3\"" + " = \"Topic Three\"]\n" + "[topic4]"; } /* (non-Javadoc) * @see org.tmapiutils.query.tolog.predicates.test.PredicateTestBase#getPredicateClass() */ public Class getPredicateClass() { return TopicNamePredicate.class; } public void testMatchOnName() throws Exception { Topic topic1 = m_tm.getTopicByID("topic1"); TopicName bn = (TopicName) topic1.getTopicNames().iterator().next(); 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(1, bn); VariableSet out = m_predicate.matches(params, new TologContext()); assertNotNull(out); assertEquals(1, out.getRows().size()); assertEquals(topic1, out.getRow(0).get(0)); } public void testMatchOnTopic() throws Exception { Topic topic3 = m_tm.getTopicByID("topic3"); 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, topic3); VariableSet out = m_predicate.matches(params, new TologContext()); assertNotNull(out); assertEquals(2, out.getRows().size()); assertEquals(topic3, out.getRow(0).get(0)); String data = ((TopicName)out.getRow(0).get(1)).getValue(); assertTrue(data.equals("Topic3") || data.equals("Topic Three")); data = ((TopicName)out.getRow(1).get(1)).getValue(); assertTrue(data.equals("Topic3") || data.equals("Topic Three")); } 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, new TologContext()); assertNotNull(out); assertEquals(4, out.getRows().size()); assertFalse(out.getColumn(a).contains(m_tm.getTopicByID("topic4"))); } public void testClosedMatch() throws Exception { Topic topic1 = m_tm.getTopicByID("topic1"); TopicName bn1 = (TopicName) topic1.getTopicNames().iterator().next(); Topic topic2 = m_tm.getTopicByID("topic2"); 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, topic1); params.set(1, bn1); VariableSet out = m_predicate.matches(params, new TologContext()); assertNotNull(out); assertEquals(1, out.getRows().size()); params.set(0, topic2); out = m_predicate.matches(params, new TologContext()); assertNotNull(out); assertEquals(0, out.getRows().size()); } } --- NEW FILE: TypePredicateTest.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test/TypePredicateTest.java,v 1.1 2005/03/06 17:33:23 lheuer Exp $ */ 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.TypePredicate; import org.tmapiutils.query.tolog.utils.VariableSet; import org.tmapi.core.Association; import org.tmapi.core.AssociationRole; import org.tmapi.core.Occurrence; import org.tmapi.core.Topic; /** * * @author Kal Ahmed (ka...@te...) */ public class TypePredicateTest extends PredicateTestBase { /** * @param name */ public TypePredicateTest(String name) { super(name); } /* (non-Javadoc) * @see org.tmapiutils.query.tolog.predicates.test.PredicateTestBase#getTestMap() */ public String getTestMap() { return "[fred:person]\n{fred, bootsize, [[12]]}\n[bigco:company]\nworks-for(fred:employee,bigco:employer)"; } /* (non-Javadoc) * @see org.tmapiutils.query.tolog.predicates.test.PredicateTestBase#getPredicateClass() */ public Class getPredicateClass() { return TypePredicate.class; } public void testMatchOnTyped() 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 = m_tm.getTopicByID("fred"); params.set(0, fred.getOccurrences().iterator().next()); VariableSet out = m_predicate.matches(params, m_context); assertNotNull(out); assertEquals(1, out.getRows().size()); assertEquals(m_tm.getTopicByID("bootsize"), out.getRow(0).get(1)); AssociationRole fredRole = (AssociationRole) fred.getRolesPlayed().iterator().next(); params.set(0, fredRole); out = m_predicate.matches(params, m_context); assertNotNull(out); assertEquals(1, out.getRows().size()); assertEquals(m_tm.getTopicByID("employee"), out.getRow(0).get(1)); params.set(0, fredRole.getParent()); out = m_predicate.matches(params, m_context); assertNotNull(out); assertEquals(1, out.getRows().size()); assertEquals(m_tm.getTopicByID("works-for"), out.getRow(0).get(1)); } public void testMatchOnType() 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(1, m_tm.getTopicByID("bootsize")); VariableSet out = m_predicate.matches(params, m_context); assertNotNull(out); assertEquals(1, out.getRows().size()); assertTrue(out.getRow(0).get(0) instanceof Occurrence); params.set(1, m_tm.getTopicByID("employee")); out = m_predicate.matches(params, m_context); assertNotNull(out); assertEquals(1, out.getRows().size()); assertTrue(out.getRow(0).get(0) instanceof AssociationRole); params.set(1, m_tm.getTopicByID("works-for")); out = m_predicate.matches(params, m_context); assertNotNull(out); assertEquals(1, out.getRows().size()); assertTrue(out.getRow(0).get(0) instanceof Association); } 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 = m_tm.getTopicByID("fred"); params.set(0, fred.getOccurrences().iterator().next()); params.set(1, m_tm.getTopicByID("bootsize")); VariableSet out = m_predicate.matches(params, m_context); assertNotNull(out); assertEquals(1, out.getRows().size()); AssociationRole fredRole = (AssociationRole) fred.getRolesPlayed().iterator().next(); params.set(0, fredRole); params.set(1, m_tm.getTopicByID("employee")); out = m_predicate.matches(params, m_context); assertNotNull(out); assertEquals(1, out.getRows().size()); params.set(0, fredRole.getParent()); params.set(1, m_tm.getTopicByID("works-for")); out = m_predicate.matches(params, m_context); assertNotNull(out); assertEquals(1, out.getRows().size()); } 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); assertEquals(4, out.getRows().size()); Iterator it = (out.getRows().iterator()); while (it.hasNext()) { List row = (List)it.next(); Object typed = row.get(0); Topic type = (Topic) row.get(1); if (typed instanceof Association) { assertEquals(((Association)typed).getType(), type); } else if (typed instanceof AssociationRole) { assertEquals(((AssociationRole)typed).getType(), type); } else if (typed instanceof Occurrence) { assertEquals(((Occurrence)typed).getType(), type); } } } } /* * $Log: TypePredicateTest.java,v $ * Revision 1.1 2005/03/06 17:33:23 lheuer * Initial tolog import * * Revision 1.2 2004/06/14 20:09:46 kal_ahmed * Updated test code to work with new Predicate interface. * * Revision 1.1 2004/06/13 10:16:48 kal_ahmed * Initial implementation of type() predicate. * */ --- NEW FILE: AssociationPredicateTest.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test/AssociationPredicateTest.java,v 1.1 2005/03/06 17:33:23 lheuer Exp $ */ package org.tmapiutils.query.tolog.predicates.test; import java.util.ArrayList; import java.util.Iterator; import org.tmapiutils.query.tolog.parser.Variable; import org.tmapiutils.query.tolog.predicates.AssociationPredicate; import org.tmapiutils.query.tolog.utils.VariableSet; import org.tmapi.core.Association; /** * @author Kal * * Describe AssociationPredicateTest here. */ public class AssociationPredicateTest extends PredicateTestBase { /** * @param name */ public AssociationPredicateTest(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"; } /* (non-Javadoc) * @see org.tmapiutils.query.tolog.predicates.test.PredicateTestBase#getPredicateClass() */ public Class getPredicateClass() { return AssociationPredicate.class; } public void testAssociationsMatch() throws Exception { ArrayList params = new ArrayList(); Variable a = new Variable("A"); 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()); Iterator it = out.getColumn(a).iterator(); while (it.hasNext()) { assertTrue(it.next() instanceof Association); } } public void testClosedMatch() throws Exception { ArrayList params = new ArrayList(); Variable a = new Variable("A"); params.add(a); m_predicate.setParameters(params); params.set(0, m_tm.getAssociations().iterator().next()); VariableSet out = m_predicate.matches(params, m_context); assertNotNull(out); assertEquals(1, out.getColumns().size()); assertEquals(1, out.getRows().size()); params.set(0, m_tm.getTopicByID("fred")); out = m_predicate.matches(params, m_context); assertNotNull(out); assertEquals(1, out.getColumns().size()); assertEquals(0, out.getRows().size()); } } /* * $Log: AssociationPredicateTest.java,v $ * Revision 1.1 2005/03/06 17:33:23 lheuer * Initial tolog import * * Revision 1.2 2004/06/14 20:09:46 kal_ahmed * Updated test code to work with new Predicate interface. * * Revision 1.1 2004/06/11 08:29:29 kal_ahmed * Added association and association-role predicates. * */ --- NEW FILE: OccurrencePredicateTest.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test/OccurrencePredicateTest.java,v 1.1 2005/03/06 17:33:23 lheuer Exp $ */ 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.OccurrencePredicate; import org.tmapiutils.query.tolog.utils.VariableSet; /** * @author Kal * * Describe OccurrencePredicateTest here. */ public class OccurrencePredicateTest extends PredicateTestBase { 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/\"}"; /** * Constructor for OccurrencePredicateTest. * @param arg0 */ public OccurrencePredicateTest(String arg0) { super(arg0); } public static void main(String[] args) { junit.textui.TestRunner.run(OccurrencePredicateTest.class); } /* (non-Javadoc) * @see org.tmapiutils.query.tolog.predicates.test.PredicateTestBase#getTestMap() */ public String getTestMap() { return TESTMAP; } /* (non-Javadoc) * @see org.tmapiutils.query.tolog.predicates.test.PredicateTestBase#getPredicateClass() */ public Class getPredicateClass() { return OccurrencePredicate.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()); assertTrue(out.getColumn(a).contains(m_tm.getObjectByID("techquila"))); assertTrue(out.getColumn(a).contains(m_tm.getObjectByID("tm4j"))); Iterator it = m_tm.getTopicByID("techquila").getOccurrences().iterator(); while (it.hasNext()) { assertTrue(out.getColumn(b).contains(it.next())); } it = m_tm.getTopicByID("tm4j").getOccurrences().iterator(); while (it.hasNext()) { assertTrue(out.getColumn(b).contains(it.next())); } } public void testTopicMatch() throws Exception { List params = new ArrayList(); Variable a = new Variable("A"); params.add(a); params.add(m_tm.getTopicByID("techquila").getOccurrences().iterator().next()); 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(m_tm.getTopicByID("techquila"))); } public void testOccurrenceMatch() throws Exception { List params = new ArrayList(); Variable a = new Variable("A"); params.add(m_tm.getTopicByID("techquila")); 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()); Iterator it = m_tm.getTopicByID("techquila").getOccurrences().iterator(); while (it.hasNext()) { assertTrue(out.getColumn(a).contains(it.next())); } } public void testClosedMatch() throws Exception { List params = new ArrayList(); Variable a = new Variab... [truncated message content] |
Update of /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25794/src/org/tmapiutils/query/tolog/predicates Added 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: Initial tolog import --- NEW FILE: TopicPredicate.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/TopicPredicate.java,v 1.1 2005/03/06 17:30:00 lheuer Exp $ */ 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 * */ 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; } } /* * $Log: TopicPredicate.java,v $ * Revision 1.1 2005/03/06 17:30:00 lheuer * Initial tolog import * * Revision 1.1 2004/06/12 14:58:50 kal_ahmed * Initial version * * Revision 1.5 2004/06/11 08:29:28 kal_ahmed * Added association and association-role predicates. * */ --- NEW FILE: AssociationPredicate.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/AssociationPredicate.java,v 1.1 2005/03/06 17:29:58 lheuer Exp $ */ 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.Association; /** * @author Kal * * Describe AssociationPredicate here. */ 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; } } /* * $Log: AssociationPredicate.java,v $ * Revision 1.1 2005/03/06 17:29:58 lheuer * Initial tolog import * * Revision 1.5 2004/06/11 08:29:28 kal_ahmed * Added association and association-role predicates. * */ --- NEW FILE: TopicMapPredicate.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/TopicMapPredicate.java,v 1.1 2005/03/06 17:30:00 lheuer Exp $ */ 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; import org.tmapi.core.TopicMap; /** * * @author Kal Ahmed (ka...@te...) */ 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 tst = (TopicMap)params.get(0); if (tst.equals(getTopicMap())) { addResultsRow(ret, new Object[] { getTopicMap()}); } } return ret; } } /* * $Log: TopicMapPredicate.java,v $ * Revision 1.1 2005/03/06 17:30:00 lheuer * Initial tolog import * * Revision 1.1 2004/06/13 10:32:28 kal_ahmed * Initial implementation of topicmap() predicate. * */ --- NEW FILE: ValuePredicate.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/ValuePredicate.java,v 1.1 2005/03/06 17:30:00 lheuer Exp $ */ 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; import org.tmapi.core.TopicName; import org.tmapi.core.DataObject; import org.tmapi.core.Occurrence; import org.tmapi.core.Topic; import org.tmapi.core.TopicMap; import org.tmapi.core.TopicMapObject; import org.tmapi.core.Variant; import org.tmapi.core.VariantContainer; import org.tmapi.core.Variant; import org.tmapi.index.core.TopicNamesIndex; import org.tmapi.index.core.OccurrencesIndex; import org.tmapi.index.core.VariantsIndex; /** * * @author Kal Ahmed (ka...@te...) */ public class ValuePredicate extends PredicateBase { private OccurrencesIndex m_odi; private TopicNamesIndex m_bni; private VariantsIndex m_vdi; 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; } /** * @param object * @param ret */ private void matchValue(TopicMapObject object, VariableSet ret) throws TologProcessingException { String value = null; if (object instanceof DataObject) { DataObject d = (DataObject)object; value = d.getValue(); if (value == null) value = d.getResource().getReference(); } else if (object instanceof TopicName) { value = ((TopicName)object).getValue(); } if (value != null) { addResultsRow(ret, new Object[] {object, value}); } } /** * @param string * @param ret */ private void matchObject(String data, VariableSet ret) throws TologProcessingException { for (Iterator it = m_odi.getOccurrencesByValue(data).iterator(); it.hasNext();) { addResultsRow(ret, new Object[] {it.next(), data}); } for (Iterator it = m_bni.getTopicNamesByValue(data).iterator(); it.hasNext();) { addResultsRow(ret, new Object[] { it.next(), data }); } for (Iterator it = m_vdi.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 { if (object instanceof DataObject) { if (data.equals(((DataObject)object).getValue())) { addResultsRow(ret, new Object[] { object, data}); } } else if (object instanceof TopicName) { if (data.equals(((TopicName)object).getValue())) { 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 { m_bni = tm.getIndexManager().getTopicNamesIndex(); if (!m_bni.isOpen()) m_bni.open(); m_odi = tm.getIndexManager().getOccurrencesIndex(); if (!m_odi.isOpen()) m_odi.open(); m_vdi = tm.getIndexManager().getVariantsIndex(); if (!m_vdi.isOpen()) m_vdi.open(); } catch (Exception 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(VariantContainer vc) throws TologProcessingException { for (Iterator it = vc.getVariants().iterator(); it.hasNext();) { Variant v = (Variant)it.next(); Variant vn = v.getVariant(); if ((vn != null) && (vn.getValue() != null)) { addResultsRow(m_vs, new Object[] { vn, vn.getValue() }); } addVariants(v); } } } } /* * $Log: ValuePredicate.java,v $ * Revision 1.1 2005/03/06 17:30:00 lheuer * Initial tolog import * * Revision 1.2 2004/09/27 14:34:00 kal_ahmed * Predicate now checks the string value of variant names as well as occurrences and base names. * * Revision 1.1 2004/06/13 09:06:43 kal_ahmed * Initial version of value() predicate. * */ --- NEW FILE: ScopePredicate.java --- /* * Created on 11-Jun-2004 * @author Kal */ 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.tmapi.core.ScopedObject; import org.tmapi.core.Topic; import org.tmapi.core.TopicMap; import org.tmapi.index.core.ThemesIndex; /** * @author Kal * * Describe ScopePredicate here. */ public class ScopePredicate extends PredicateBase { private ThemesIndex m_ti; 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 { for (Iterator themes = m_ti.getScopingTopics().iterator(); themes.hasNext();){ Topic theme = (Topic)themes.next(); for (Iterator scoped = m_ti.getScopedObjects(theme).iterator(); scoped.hasNext();) { addResultsRow(ret, new Object[] {scoped.next(), theme}); } } } /** * @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 theme, VariableSet ret) throws TologProcessingException { for (Iterator it = m_ti.getScopedObjects(theme).iterator(); it.hasNext();) { addResultsRow(ret, new Object[] {it.next(), theme}); } } /** * @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 { m_ti = tm.getIndexManager().getThemesIndex(); if (!m_ti.isOpen()) { m_ti.open(); } } catch (Exception ex) { throw new TologParserException("Unable to initialise indexes for " + PREDICATE_NAME, ex); } } } --- NEW FILE: AssociationRolePredicate.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/AssociationRolePredicate.java,v 1.1 2005/03/06 17:29:58 lheuer Exp $ */ 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.Association; import org.tmapi.core.AssociationRole; /** * @author Kal * * Describe AssociationRolePredicate here. */ 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).getParent(), 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 member, VariableSet ret) throws TologProcessingException { if (member.getParent().equals(association)) { addResultsRow(ret, new Object[] {association, member}); } } /** * @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()}); } } } /* * $Log: AssociationRolePredicate.java,v $ * Revision 1.1 2005/03/06 17:29:58 lheuer * Initial tolog import * * Revision 1.1 2004/06/11 08:29:29 kal_ahmed * Added association and association-role predicates. * */ --- NEW FILE: SubjectLocatorPredicate.java --- /* * Created on 11-Jun-2004 * @author Kal */ package org.tmapiutils.query.tolog.predicates; import java.util.Iterator; import java.util.List; import org.tm4j.net.Locator; 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 * * Describe SubjectIdentifierPredicate here. */ public class SubjectLocatorPredicate extends PredicateBase { 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 t = (Topic)it.next(); if (t.getSubjectLocators() != null) { addResultsRow(ret, new Object[] { t, t.getSubjectLocators()}); } } } /** * @param topic * @param locator * @param ret */ private void closedMatch(Topic t, Locator locator, VariableSet ret) throws TologProcessingException { if (t.getSubjectLocators().equals(locator)) { addResultsRow(ret, new Object[] { t, locator}); } } /** * @param locator * @param ret */ private void matchTopic(Locator locator, VariableSet ret) throws TologProcessingException { Topic t = getTopicMap().getTopicBySubject(locator); if (t != null) { addResultsRow(ret, new Object[] { t, locator }); } } /** * @param topic * @param ret */ private void matchSubjectLocator(Topic t, VariableSet ret) throws TologProcessingException { addResultsRow(ret, new Object[] { t, t.getSubjectLocators()}); } } --- NEW FILE: ValueLikePredicate.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/ValueLikePredicate.java,v 1.1 2005/03/06 17:30:00 lheuer Exp $ */ package org.tmapiutils.query.tolog.predicates; 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.tmapi.core.TopicMap; import org.tmapi.core.TopicMapObject; import org.tmapi.core.index.IndexManager; import org.tmapi.core.index.text.FullTextIndex; import org.tmapi.core.index.text.QueryHit; import org.tmapi.core.index.text.QueryResult; /** * * @author Kal Ahmed (ka...@te...) */ public class ValueLikePredicate extends PredicateBase { private FullTextIndex m_txtIx; public static final String PREDICATE_NAME="value-like"; private static final ParameterInfo[] PARAM_INFO = new ParameterInfo[] { new ParameterInfo(true), new ParameterInfo(true, String.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(); Object o = params.get(0); String srchString = (String)params.get(1); initialiseResultsSet(ret); if (o instanceof Variable) { getAllMatches(srchString, ret); } else if (o instanceof TopicMapObject) { getObjectMatches((TopicMapObject)o, srchString, ret); } return ret; } /** * @param srchString * @param ret */ private void getAllMatches(String srchString, VariableSet ret) throws TologProcessingException { try { QueryResult qr = m_txtIx.findByText(srchString, true); for (int i = 0; i < qr.size(); i++) { QueryHit qh = qr.getHit(i); addResultsRow(ret, new Object[] { qh.getObject(), srchString }); } } catch (TologProcessingException ex) { throw ex; } catch (Exception ex) { throw new TologProcessingException("Error processing full-text query in " + PREDICATE_NAME + " predicate.", ex); } } /** * @param object * @param srchString * @param ret */ private void getObjectMatches(TopicMapObject object, String srchString, VariableSet ret) throws TologProcessingException { try { QueryResult qr = m_txtIx.findByText(srchString, true); for (int i = 0; i < qr.size(); i++) { QueryHit qh = qr.getHit(i); if (qh.getObject().equals(object)) { addResultsRow(ret, new Object[] { object, srchString }); } } } catch (TologProcessingException ex) { throw ex; } catch (Exception ex) { throw new TologProcessingException("Error processing full-text query in " + PREDICATE_NAME + " predicate.", ex); } } /* (non-Javadoc) * @see org.tmapiutils.query.tolog.parser.Predicate#initialise(org.tmapi.core.TopicMap) */ public void initialise(TopicMap tm) throws TologParserException { super.initialise(tm); IndexManager ixMgr = tm.getIndexManager(); try { m_txtIx = (FullTextIndex) ixMgr.getIndex(FullTextIndex.class); if (m_txtIx == null) { throw new TologParserException("No full-text index is registered for this topic map. '" + PREDICATE_NAME + "' predicates cannot be used."); } if (!m_txtIx.isOpen()) { m_txtIx.open(); } m_txtIx.reindex(); } catch (TologParserException ex) { throw ex; } catch (Exception ex) { throw new TologParserException("Error initialising text index for predicate " + PREDICATE_NAME, ex); } } } /* * $Log: ValueLikePredicate.java,v $ * Revision 1.1 2005/03/06 17:30:00 lheuer * Initial tolog import * * Revision 1.1 2004/06/13 11:30:26 kal_ahmed * Initial implementation of value-like predicate. * */ --- NEW FILE: SourceLocatorsPredicate.java --- /* * Created on 11-Jun-2004 * @author Kal */ package org.tmapiutils.query.tolog.predicates; import java.util.Iterator; import java.util.List; import org.tm4j.net.Locator; import org.tmapiutils.query.tolog.TologProcessingException; import org.tmapiutils.query.tolog.parser.Variable; import org.tmapiutils.query.tolog.utils.VariableSet; import org.tmapi.core.TopicMapObject; /** * @author Kal * * Describe SourceLocatorsPredicate here. */ public class SourceLocatorsPredicate extends PredicateBase { public static final String PREDICATE_NAME = "source-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 obj = params.get(0); Object loc = params.get(1); VariableSet ret = new VariableSet(); initialiseResultsSet(ret); if ((obj instanceof TopicMapObject) && (loc instanceof Variable)) { matchLocators((TopicMapObject)obj, ret); } else if ((obj instanceof Variable) && (loc instanceof Locator)) { matchObject((Locator)loc, ret); } else if ((obj instanceof TopicMapObject) && (loc instanceof Locator)) { closedMatch((TopicMapObject)obj, (Locator)loc, ret); } else if ((obj instanceof Variable) && (loc instanceof Variable)) { openMatch(ret); } return ret; } /** * @param ret */ private void openMatch(VariableSet ret) throws TologProcessingException { for (Iterator it = getTopicMap().getObjects().iterator(); it.hasNext();) { TopicMapObject tmo = (TopicMapObject)it.next(); for (Iterator l = tmo.getSourceLocators().iterator(); l.hasNext();) { addResultsRow(ret, new Object[] {tmo, l.next()}); } } } /** * @param object * @param locator * @param ret */ private void closedMatch(TopicMapObject tmo, Locator locator, VariableSet ret) throws TologProcessingException { for (Iterator l = tmo.getSourceLocators().iterator(); l.hasNext();) { if (l.next().equals(locator)) { addResultsRow(ret, new Object[] {tmo, locator}); } } } /** * @param locator * @param ret */ private void matchObject(Locator locator, VariableSet ret) throws TologProcessingException { TopicMapObject tmo = getTopicMap().getObjectBySourceLocator(locator); if (tmo != null) { addResultsRow(ret, new Object[] {tmo, locator}); } } /** * @param object * @param ret */ private void matchLocators(TopicMapObject tmo, VariableSet ret) throws TologProcessingException { for (Iterator it = tmo.getSourceLocators().iterator(); it.hasNext();) { addResultsRow(ret, new Object[] {tmo, it.next()}); } } } --- NEW FILE: OccurrencePredicate.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/OccurrencePredicate.java,v 1.1 2005/03/06 17:30:00 lheuer Exp $ */ 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.Occurrence; import org.tmapi.core.Topic; /** * @author Kal * * Describe OccurrencePredicate here. */ public class OccurrencePredicate extends PredicateBase { public static final String PREDICATE_NAME = "occurrence"; 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 { VariableSet ret = new VariableSet(); initialiseResultsSet(ret); Object p1 = params.get(0); Object p2 = params.get(1); if ((p1 instanceof Variable) && (p2 instanceof Variable)) { openMatch((Variable)p1, (Variable)p2, ret); } else if ((p1 instanceof Variable) && (p2 instanceof Occurrence)) { addResultsRow(ret, new Object[] {((Occurrence)p2).getParent(), p2}); } else if ((p1 instanceof Topic) && (p2 instanceof Variable)) { getOccurrences((Topic)p1, (Variable)p2, ret); } else if ((p1 instanceof Topic) && (p2 instanceof Occurrence)) { if (((Occurrence)p2).getParent().equals(p1)) { addResultsRow(ret, new Object[] {p1, p2}); } } return ret; } /** * @param topic * @param variable * @param ret * @return */ private void getOccurrences(Topic topic, Variable variable, VariableSet ret) throws TologProcessingException { Iterator it = topic.getOccurrences().iterator(); while (it.hasNext()) { addResultsRow(ret, new Object[] {topic, it.next()}); } } /** * @param variable * @param variable2 * @param ret * @return */ private void openMatch(Variable topic, Variable occurrence, VariableSet ret) throws TologProcessingException { Iterator it = getTopicMap().getTopics().iterator(); while (it.hasNext()) { getOccurrences((Topic)it.next(), occurrence, ret); } } } /* * $Log: OccurrencePredicate.java,v $ * Revision 1.1 2005/03/06 17:30:00 lheuer * Initial tolog import * * Revision 1.2 2004/06/10 08:19:40 kal_ahmed * Added standard file header and footer. * */ --- NEW FILE: TopicNamePredicate.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/TopicNamePredicate.java,v 1.1 2005/03/06 17:30:00 lheuer Exp $ */ 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.predicates.PredicateBase; import org.tmapiutils.query.tolog.utils.VariableSet; import org.tmapi.core.TopicName; import org.tmapi.core.Topic; import org.tmapi.core.TopicMap; import org.tmapi.core.index.IndexManagerException; import org.tmapi.index.core.TopicNamesIndex; /** * * @author Henke * */ public class TopicNamePredicate extends PredicateBase { private TopicNamesIndex idx=null; public static final String PREDICATE_NAME = "topic-name"; /* (non-Javadoc) * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getParamInfo() */ public ParameterInfo[] getParamInfo() { ParameterInfo[] info = new ParameterInfo[2]; info[0] = new ParameterInfo(true); info[1] = new ParameterInfo(true); return 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 paramTopic = params.get(0); Object paramName = params.get(1); if((paramName instanceof Variable) && (paramTopic instanceof Variable)) { Iterator itTopics = getTopicMap().getTopics().iterator(); while(itTopics.hasNext()) { Topic top = (Topic)itTopics.next(); Iterator itNames=top.getTopicNames().iterator(); while(itNames.hasNext()) { TopicName name = (TopicName)itNames.next(); addResultsRow(ret, new Object[] {top, name}); } } } else if((paramName instanceof TopicName) && (paramTopic instanceof Variable)) { /* -- Original version, returns all names with the same data string. TopicName name = (TopicName)paramName; Iterator it= idx.getTopicNamesByValue(name.getValue()).iterator(); while(it.hasNext()) { TopicName tmp =(TopicName)it.next(); Topic top = name.getParent(); addResultsRow(ret, new Object[] {top, tmp}); } */ /* Simple version returns only the parent of the paramName parameter */ addResultsRow(ret, new Object [] { ((TopicName)paramName).getParent(), paramName}); } else if((paramName instanceof Variable) && (paramTopic instanceof Topic)) { Topic top = (Topic)paramTopic; Iterator it=top.getTopicNames().iterator(); while(it.hasNext()) { TopicName name = (TopicName)it.next(); addResultsRow(ret, new Object[] {top, name}); } } else if((paramName instanceof TopicName) && (paramTopic instanceof Topic)) { // KA: Only add the row if paramName is a name of paramTopic if (((TopicName)paramName).getParent().equals(paramTopic)) { addResultsRow(ret, new Object[] {paramTopic, paramName}); } } return ret; } /* (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 { idx = getTopicMap().getIndexManager().getTopicNamesIndex(); } catch (IndexManagerException e) { throw new TologParserException("Cannot initialize " + getPredicateName() + " predicate class", e); } } } /* * $Log: TopicNamePredicate.java,v $ * Revision 1.1 2005/03/06 17:30:00 lheuer * Initial tolog import * * Revision 1.2 2004/06/14 21:31:17 kal_ahmed * Added TopicNamePredicate to builtins. * * Revision 1.1 2004/06/14 20:08:05 kal_ahmed * Initial version. Contributed by Stefan Henke. * */ --- NEW FILE: TypePredicate.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/TypePredicate.java,v 1.1 2005/03/06 17:30:00 lheuer Exp $ */ 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.tmapi.core.Association; import org.tmapi.core.AssociationRole; import org.tmapi.core.Occurrence; import org.tmapi.core.Topic; import org.tmapi.core.TopicMap; import org.tmapi.core.TopicMapObject; import org.tmapi.index.core.AssociationTypesIndex; import org.tmapi.index.core.AssociationRolesIndex; import org.tmapi.index.core.OccurrencesIndex; /** * * @author Kal Ahmed (ka...@te...) */ public class TypePredicate extends PredicateBase { private AssociationRolesIndex m_mti; private OccurrencesIndex m_oti; private AssociationTypesIndex m_ati; public static final String PREDICATE_NAME = "type"; 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 typed = params.get(0); Object type = params.get(1); VariableSet ret = new VariableSet(); initialiseResultsSet(ret); if ((typed instanceof TopicMapObject) && (type instanceof Variable)) { getType((TopicMapObject)typed, ret); } else if ((typed instanceof Variable) && (type instanceof Topic)) { getTyped((Topic)type, ret); } else if ((typed instanceof TopicMapObject) && (type instanceof Topic)) { closedMatch((TopicMapObject)typed, (Topic) type, ret); } else if ((typed instanceof Variable) && (type instanceof Variable)) { openMatch(ret); } return ret; } /** * @param object * @param ret */ private void getType(TopicMapObject object, VariableSet ret) throws TologProcessingException { Topic type = null; if (object instanceof Association) { type = ((Association)object).getType(); } else if (object instanceof AssociationRole) { type = ((AssociationRole)object).getType(); } else if (object instanceof Occurrence) { type = ((Occurrence)object).getType(); } if (type != null) { addResultsRow(ret, new Object[] { object, type }); } } /** * @param topic * @param ret */ private void getTyped(Topic type, VariableSet ret) throws TologProcessingException { Iterator it = m_ati.getAssociationsByType(type).iterator(); addInstances(type, it, ret); it = m_oti.getOccurrencesByType(type).iterator(); addInstances(type, it, ret); it = m_mti.getAssociationRolesOfType(type).iterator(); addInstances(type, it, ret); } /** * @param type * @param it * @param ret */ private void addInstances(Topic type, Iterator it, VariableSet ret) throws TologProcessingException { while (it.hasNext()) { addResultsRow(ret, new Object[] { it.next(), type }); } } /** * @param object * @param topic * @param ret */ private void closedMatch(TopicMapObject typed, Topic type, VariableSet ret) throws TologProcessingException { boolean match = false; if (typed instanceof Association) { match = type.equals(((Association)typed).getType()); } else if (typed instanceof AssociationRole) { match = type.equals(((AssociationRole)typed).getType()); } else if (typed instanceof Occurrence) { match = type.equals(((Occurrence)typed).getType()); } if (match) { addResultsRow(ret, new Object[] { typed, type }); } } /** * @param ret */ private void openMatch(VariableSet ret) throws TologProcessingException { for (Iterator types = m_ati.getAssociationTypes().iterator(); types.hasNext();) { Topic type = (Topic)types.next(); for (Iterator instances = m_ati.getAssociationsByType(type).iterator(); instances.hasNext();) { addResultsRow(ret, new Object[] { instances.next(), type }); } } for (Iterator types = m_oti.getOccurrenceTypes().iterator(); types.hasNext();) { Topic type = (Topic)types.next(); for (Iterator instances = m_oti.getOccurrencesByType(type).iterator(); instances.hasNext();) { addResultsRow(ret, new Object[] { instances.next(), type }); } } for (Iterator types = m_mti.getAssociationRoleTypes().iterator(); types.hasNext();) { Topic type = (Topic)types.next(); for (Iterator instances = m_mti.getAssociationRolesOfType(type).iterator(); instances.hasNext();) { addResultsRow(ret, new Object[] { instances.next(), type }); } } } /* (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 { m_ati = tm.getIndexManager().getAssociationTypesIndex(); if (!m_ati.isOpen()) m_ati.open(); m_oti = tm.getIndexManager().getOccurrencesIndex(); if (!m_oti.isOpen()) m_oti.open(); m_mti = tm.getIndexManager().getAssociationRolesIndex(); if (!m_mti.isOpen()) m_mti.open(); } catch (Exception ex) { throw new TologParserException("Error initialising indexes for predicate " + PREDICATE_NAME, ex); } } } /* * $Log: TypePredicate.java,v $ * Revision 1.1 2005/03/06 17:30:00 lheuer * Initial tolog import * * Revision 1.1 2004/06/13 10:16:47 kal_ahmed * Initial implementation of type() predicate. * */ --- NEW FILE: PredicateBase.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/PredicateBase.java,v 1.1 2005/03/06 17:30:00 lheuer Exp $ */ package org.tmapiutils.query.tolog.predicates; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Map; import org.tmapiutils.query.tolog.TologParserException; import org.tmapiutils.query.tolog.TologProcessingException; import org.tmapiutils.query.tolog.parser.Placeholder; import org.tmapiutils.query.tolog.parser.PlayerRoleVarPair; import org.tmapiutils.query.tolog.parser.Predicate; import org.tmapiutils.query.tolog.parser.Variable; import org.tmapiutils.query.tolog.utils.TologContext; import org.tmapiutils.query.tolog.utils.VariableSet; import org.tmapi.core.Topic; import org.tmapi.core.TopicMap; /** * * @author Kal Ahmed (ka...@te...) */ public abstract class PredicateBase implements Predicate { private List m_params; private TopicMap m_tm; public void initialise(TopicMap tm) throws TologParserException { m_tm = tm; } public TopicMap getTopicMap() { return m_tm; } /* (non-Javadoc) * @see org.tmapiutils.query.tolog.Predicate#setParameters(java.util.List) */ public void setParameters(List params) throws TologParserException { m_params = new ArrayList(); m_params.addAll(params); validateParameters(); } public VariableSet matches(List params, TologContext context) throws TologProcessingException { return matches(params); } public abstract VariableSet matches(List params) throws TologProcessingException ; public Object getParameterValue(int paramIx, Map paramMap) { Object param = m_params.get(paramIx); if (param instanceof Variable) { Object ret = paramMap.get(((Variable)param).getName()); if (ret != null) return ret; } else if (param instanceof PlayerRoleVarPair) { PlayerRoleVarPair src = (PlayerRoleVarPair)param; PlayerRoleVarPair ret = new PlayerRoleVarPair(src.getPlayerTopic(), src.getRoleTopic()); if (src.getPlayerTopic() == null) { Object o = paramMap.get(src.getPlayerVar()); if (o == null) { ret.setPlayerVar(src.getPlayerVar()); } else if (o instanceof Variable) { ret.setPlayerVar((Variable)o); } else if (o instanceof Topic) { ret.setPlayerTopic((Topic)o); } else { throw new RuntimeException("Type mismatch in role-player parameter. Variable " + src.getPlayerVar().getName() + " is not a Topic. Got " + o.toString()); } } if (src.getRoleTopic() == null) { if (src.getRoleVar() != null) { Object o = paramMap.get(src.getRoleVar()); if (o == null) { ret.setRoleVar(src.getRoleVar()); } else if (o instanceof Variable) { ret.setRoleVar((Variable)o); } else if (o instanceof Topic) { ret.setRoleTopic((Topic)o); } else { throw new RuntimeException("Type mismatch in role-player parameter. Variable " + src.getPlayerVar().getName() + " is not a Topic."); } } } return ret; } return param; } public List getParameters() { return m_params; } public void validateParameters() throws TologParserException { if (m_params.size() < getMinParamCount()) { throw new TologParserException("Insufficient parameters for " + getPredicateName() + ". Predicate expects at least " + getMinParamCount() + " parameters."); } if (m_params.size() > getMaxParamCount()) { throw new TologParserException("Too many parameters for " + getPredicateName() + ". Predicate expects no more than " + getMaxParamCount() + " parameters."); } for (int ix = 0; ix < m_params.size(); ix++) { Object o = m_params.get(ix); if (o instanceof Variable) { if (!isVariableAllowed(ix)) { throw new TologParserException("The predicate " + getPredicateName() + " does not allow a variable to be used for parameter " + String.valueOf(ix+1) + "."); } } else if (!(o instanceof Placeholder)) { if (!validateParamType(ix, o.getClass())) { throw new TologParserException("Invalid parameter type for parameter " + getPredicateName() + " at parameter " + String.valueOf(ix + 1) + ". Invalid object type was " + o.getClass()); } } } } /** * Returns the minimum number of parameters accepted by this predicate. * If not specified, defaults to the value returned by {@link #getParamCount()} */ public int getMinParamCount() { return getParamCount(); } /** * Returns the maximum number of parameters accepted by this predicate. * If not specified, defaults to the value returned by {@link #getParamCount()} */ public int getMaxParamCount() { return getParamCount(); } /** * Returns an array of ParameterInfo instances which describe the * constraints for the parameters accepted by this predicate. If * getParamCount() is not overriden, then the size of the returned * array also determines the allowed parameter count for the predicate. * @return an array of ParameterInfo items, one for each parameter allowed * by this predicate, or null if the predicate does not allow any parameters at all. */ public abstract ParameterInfo [] getParamInfo(); /** * Returns the number of parameters accepted by this predicate. * If not specified, defaults to the number of ParameterInfo instances passed * to the setParameterInfo(ParameterInfo[]) method. */ public int getParamCount() { ParameterInfo [] pi = getParamInfo(); return pi == null ? 0 : pi.length; } /** * Indicates if a variable is allowed to be specified for a predicate parameter. * This test is performed when the predicate is parsed, not when it is executed, * so cannot be used to restrict parameters to being bound when the predicate * is executed. * @param ix the index of the predicate parameter being tested * @return <code>true</code> if a variable may appear at this parameter index, * <code>false</code> if the value must be a Topic. */ public boolean isVariableAllowed(int ix) { ParameterInfo pi = getParamInfo()[ix]; if (pi != null) { return pi.isVariableAllowed(); } else { return true; } } /** * Validates that a parameter is of the expected type. * @param ix the index of the predicate parameter being tested * @param paramType the type of the predicate parameter * @return true if <code>paramType</code> is an allowed type * for the parameter at <code>ix</code>, false otherwise. */ public boolean validateParamType(int ix, Class paramType) { ParameterInfo pi = getParamInfo()[ix]; if (pi != null) { return pi.validateParamType(paramType); } else { return true; } } public void initialiseResultsSet(VariableSet resultsSet) { Iterator it = getParameters().iterator(); while (it.hasNext()) { Object param = it.next(); if (param instanceof Variable) { resultsSet.addColumn(param); } } } public void addResultsRow(VariableSet resultsSet, Object[] results) throws TologProcessingException { int max = getParameters().size(); ArrayList row = new ArrayList(); for (int i = 0; i < max; i++) { if (getParameters().get(i) instanceof Variable) { row.add(results[i]); } } resultsSet.addRow(row); } /** * Returns the name of this predicate. This name is used in exception * message strings. * @return the predicate name */ public abstract String getPredicateName(); public String toString(){ StringBuffer ret = new StringBuffer(); ret.append(getPredicateName()); ret.append("("); Iterator it = getParameters().iterator(); while (it.hasNext()) { ret.append(it.next().toString()); if (it.hasNext()) { ret.append(", "); } } ret.append(")"); return ret.toString(); } /** * Parameter description information for predicates derived from the PredicateBase * abstract class. This class keeps track of two pieces of information for a parameter. * The first, <code>variableAllowed</code>, is a boolean flag which is true if it is allowable * for a variable to be used for this parameter. The second <code>allowedTypes</code> * is an array of Class instances which define the allowed Class (or interface) that * the parameter value should implement. The parameter is required to be assignable * to one of the classes specified in <code>allowedTypes</code>. * @author Kal Ahmed (ka...@te...) */ public static class ParameterInfo { private boolean m_varAllowed; private Class[] m_allowedTypes; /** * Creates information for a parameter where the type of the parameter * value is unconstrainted. * @param variableAllowed indicates whether or not a variable is allowed for this parameter. */ public ParameterInfo(boolean variableAllowed) { m_varAllowed = variableAllowed; m_allowedTypes = null; } /** * Creates information for a parameter where the parameter type is * constrainted to a single class * @param variableAllowed indicates whether or not a variable is allowed for this parameter. * @param allowedType the type allowed for this parameter value. */ public ParameterInfo(boolean variableAllowed, Class allowedType) { m_varAllowed = variableAllowed; m_allowedTypes = new Class[] {allowedType}; } /** * Creates information for a parameter where the parameter type can be one * of a list of allowed types. * @param variableAllowed indicates whether or not a variable is allowed for this parameter. * @param allowedTypes an array of the types allowed for this parameter value. */ public ParameterInfo(boolean variableAllowed, Class[] allowedTypes) { m_varAllowed = variableAllowed; m_allowedTypes = allowedTypes; } public boolean isVariableAllowed() { return m_varAllowed; } public boolean validateParamType(Class paramType) { if (m_allowedTypes == null) return true; for (int i = 0; i < m_allowedTypes.length; i++) { if (m_allowedTypes[i].isAssignableFrom(paramType)) return true; } return false; } } } /* * $Log: PredicateBase.java,v $ * Revision 1.1 2005/03/06 17:30:00 lheuer * Initial tolog import * * Revision 1.8 2004/07/20 07:12:07 kal_ahmed * getParameters() now returns a direct reference to the parameters which can be modified. * * Revision 1.7 2004/07/16 13:51:36 kal_ahmed * Fixes for tolog engine handling of rules and rule-recursion. * * Revision 1.6 2004/06/16 21:21:43 kal_ahmed * Tolog queries may now contain replaceable references specified in an Object array parameter to the QueryEvaluator at evaluation time. * * Revision 1.5 2004/06/13 19:44:30 kal_ahmed * Added a fix and test for handling recursive rules definitions. * * Revision 1.4 2004/06/13 17:17:59 kal_ahmed * Added registration of builtin predicates. Fixed rule expansion code to handle player/role pairs correctly. * * Revision 1.3 2004/06/09 22:15:08 kal_ahmed * Fixed parser to disallow player:role pairs in predicates other than dynamic association predicates. Fixed initialisation of extension predicates. Added DirectInstanceOfPredicate extension to in-memory query evaluator. * * Revision 1.2 2004/06/09 20:20:30 kal_ahmed * Major reworking of the predicate interfaces and internal implementation of VariableSet to reduce the use of HashMaps. * * Revision 1.1 2004/06/07 20:31:59 kal_ahmed * Completed work on projection and sorting. Performed a bit more code reorganisation. Added DirectInstanceOfPredicate. * * Revision 1.2 2004/06/02 19:22:13 kal_ahmed * Added support for parsing rules and including them in queries. * * Revision 1.1 2004/05/30 22:08:25 kal_ahmed * Initial version of tolog 1.0 engine * */ --- NEW FILE: SubjectIdentifierPredicate.java --- /* * Created on 11-Jun-2004 * @author Kal */ package org.tmapiutils.query.tolog.predicates; import java.util.Iterator; import java.util.List; import org.tm4j.net.Locator; import org.tmapiutils.query.tolog.TologProcessingException; import org.tmapiutils.query.tolog.parser.Variable; import org.tmapiutils.query.t... [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-serv25475/src/org/tmapiutils/query/tolog/parser Added 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 tolog.g Log Message: Initial tolog import --- NEW FILE: PlayerRolePair.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/parser/PlayerRolePair.java,v 1.1 2005/03/06 17:29:06 lheuer Exp $ */ package org.tmapiutils.query.tolog.parser; import org.tmapiutils.query.tolog.utils.ReferenceUtils; import org.tmapi.core.Topic; /** * * @author Kal Ahmed (ka...@te...) */ 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); } } /* * $Log: PlayerRolePair.java,v $ * Revision 1.1 2005/03/06 17:29:06 lheuer * Initial tolog import * * Revision 1.3 2004/06/07 20:31:15 kal_ahmed * Completed work on projection and sorting. Performed a bit more code reorganisation. Added DirectInstanceOfPredicate. * * Revision 1.2 2004/06/03 19:55:16 kal_ahmed * Created utils package to hold common utility classes for Tolog implementations. * * Revision 1.1 2004/06/03 19:47:22 kal_ahmed * Separated parser and parsed query representation classes into a sub-package. * * Revision 1.1 2004/05/30 22:08:25 kal_ahmed * Initial version of tolog 1.0 engine * */ --- NEW FILE: tolog.g --- header { package org.tm4j.tologx.parser; } { /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/parser/tolog.g,v 1.1 2005/03/06 17:29:07 lheuer Exp $ */ import org.tm4j.net.Locator; import org.tm4j.net.LocatorFactoryException; import org.tm4j.net.LocatorResolutionException; import org.tm4j.topicmap.Topic; import org.tm4j.topicmap.TopicMap; import org.tm4j.topicmap.TopicMapObject; import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import java.io.IOException; import java.net.URL; import java.net.MalformedURLException; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Stack; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.tm4j.tologx.TologParserException; import org.tm4j.tologx.predicates.DynamicAssociationPredicate; } /** * INTERNAL: Parser for the tolog syntax. */ class TologParser extends Parser; options { defaultErrorHandler = false; k = 2; } { private static final Log m_log = LogFactory.getLog(TologParser.class); private Stack m_clauseStack = new Stack(); private ClauseList m_currClauseList; private Object m_refObject; private String m_varName; private TopicMap m_tm; private Predicate m_predicate; private List m_predicateParams; private Map m_predicatesByID = new HashMap(); private Map m_rulesByName = new HashMap(); private TologRule m_rule; private List m_rules = null; private Object m_param; private PlayerRoleVarPair m_prp; private Projection m_proj; private Sorting m_sorting; private int m_pageStart = 0; private int m_pageLength = -1; private boolean m_pageLengthSet; private Locator m_baseLoc; private String m_prefix; private Map m_prefixMap = new HashMap(); private NEClause m_nec = null; private OrClause m_oc = null; private NotClause m_nc = null; private String m_identifier = null; private Class m_dynAssocPredicate = DynamicAssociationPredicate.class; public void setTopicMap(TopicMap topicmap) { m_tm = topicmap; } private Object getObjectByIdent(String ident) throws TologParserException { try { Object tmo; if (ident.startsWith("i\"")) { String si = ident.substring(2, ident.length() - 1); Locator l = m_tm.getBaseLocator().resolveRelative(si); tmo = m_tm.getTopicBySubjectIndicator(l); if (tmo == null) { throw new TologParserException("No topic found in topic map with subject indicator: " + si); } } else if (ident.startsWith("a\"")) { String sa = ident.substring(2, ident.length() - 1); Locator l = m_tm.getBaseLocator().resolveRelative(sa); tmo = m_tm.getTopicBySubject(l); if (tmo == null) { throw new TologParserException("No topic found in topic map with subject address: " + sa); } } else if (ident.startsWith("s\"")) { String src = ident.substring(2, ident.length() - 1); Locator l = m_tm.getBaseLocator().resolveRelative(src); tmo = m_tm.getObjectBySourceLocator(l); if (tmo == null) { throw new TologParserException("No topic found in topic map with source locator address: " + src); } } else if (ident.startsWith("@")) { String id = ident.substring(1); tmo = m_tm.getObjectByID(id); if (tmo == null) { throw new TologParserException("No object found in topic map with id: " + id); } } else if (ident.startsWith("%")) { int ref = Integer.parseInt(ident.substring(1)); tmo = new Placeholder(ref); } else { Locator l = m_tm.getBaseLocator().resolveRelative("#" + ident); tmo = m_tm.getObjectBySourceLocator(l); if (tmo == null) { throw new TologParserException("No object in topic map with source locator " + l.getAddress()); } } return tmo; } catch (LocatorResolutionException ex) { throw new TologParserException("Invalid topic identifier " + ident + ". The identifier cannot be resolved to a URI fragment identifier."); } } public void setBaseLocator(Locator baseLoc) { m_baseLoc = baseLoc; } public void setPrefix(String prefix) { m_prefix = prefix; } public Map getRules() { return m_rulesByName; } public void setRules(Map m) { m_rulesByName.clear(); m_rulesByName.putAll(m); } public void setPrefixRules(Map m) { Iterator keys = m.keySet().iterator(); while (keys.hasNext()) { String prefix = (String)keys.next(); Map rules = (Map)m.get(prefix); Iterator ruleNames = rules.keySet().iterator(); while (ruleNames.hasNext()) { String ruleName = (String)ruleNames.next(); String fullName = prefix + ":" + ruleName; addRule(fullName, (TologRule)rules.get(ruleName)); } } } public void setPredicates(Map m) { m_predicatesByID.clear(); m_predicatesByID.putAll(m); } public void setDynamicAssociationPredicateClass(Class c) { m_dynAssocPredicate = c; } private void importModule(String modSrc, String modPrefix) throws TologParserException { // Hack to remove enclosing quotes from URL production. if (modSrc.startsWith("\"")) { modSrc = modSrc.substring(1, modSrc.length() - 1); } m_log.debug(modSrc); try { if (m_log.isDebugEnabled()) m_log.debug("START importModule from " + modSrc + " with prefix " + modPrefix); Locator moduleLoc = null; if (m_baseLoc == null) { if (m_tm.getBaseLocator() != null) { m_log.debug("Resolving name against topic map base locator: " + m_tm.getBaseLocator().getAddress()); moduleLoc = m_tm.getBaseLocator().resolveRelative(modSrc); } else { moduleLoc = m_tm.getLocatorFactory().createLocator("URI", modSrc); } } else { m_log.debug("Resolving name against module base locator: " + m_baseLoc.getAddress()); moduleLoc = m_baseLoc.resolveRelative(modSrc); } m_log.debug("Resolved module locator: "+ moduleLoc.getAddress()); InputStream is = null; try { m_log.debug("Trying address as URL..."); URL u = new URL(moduleLoc.getAddress()); is = u.openStream(); } catch (MalformedURLException ex) { m_log.debug("Trying address as file name..."); File f = new File(moduleLoc.getAddress()); m_log.debug("Got new file: "+ f.getAbsolutePath()); if (f.exists()) { is = new FileInputStream(f); } else { throw new TologParserException("Unable to process module reference " + moduleLoc.getAddress() + " as either a URL or a file name."); } } TologParser p = new TologParser(new TologLexer(is)); p.setTopicMap(m_tm); p.setBaseLocator(moduleLoc); p.setPrefix(modPrefix); p.module(); Map moduleRules = p.getRules(); if (m_log.isDebugEnabled()) m_log.debug("Parse of module " + moduleLoc.getAddress() + " completed. Parser reports " + moduleRules.size() + " rules."); Iterator it = moduleRules.keySet().iterator(); while (it.hasNext()) { String ruleName = (String)it.next(); if (ruleName.indexOf(":") < 0) { addRule(modPrefix + ":" + ruleName, (TologRule)moduleRules.get(ruleName)); } } if (m_log.isDebugEnabled()) m_log.debug("END importModule " + modSrc + " as " + modPrefix); } catch (LocatorFactoryException ex) { throw new TologParserException("Unable to resolve module reference " + modSrc + " to a valid URL.", ex); } catch (LocatorResolutionException ex) { throw new TologParserException("Unable to resolve module reference " + modSrc + " to a valid URL.", ex); } catch (MalformedURLException ex) { throw new TologParserException("Unable to open module reference " + modSrc + ".", ex); } catch (IOException ex) { throw new TologParserException("Unable to read module from reference " + modSrc + ".", ex); } catch (ANTLRException ex) { throw new TologParserException("Error parsing module from reference " + modSrc + ".", ex); } } private void addRule(String name, TologRule rule) { m_predicatesByID.put(name, TologRule.class); m_rulesByName.put(name, rule); } } module throws TologParserException : (directive)* (r:rule)* ; directive throws TologParserException : import_module | prefixmap ; import_module throws TologParserException : "import" mod_src:URL "as" mod_prefix:NAME { importModule(mod_src.getText(), mod_prefix.getText()); } ; prefixmap throws TologParserException : "using" prefix:NAME "for" (INDURL { m_prefixMap.put(prefix, LT(0).getText()); }| ADDURL { m_prefixMap.put(prefix, LT(0).getText()); }| SRCURL { m_prefixMap.put(prefix, LT(0).getText()); }| OBJID { m_prefixMap.put(prefix, LT(0).getText()); }) ; rule returns [TologRule r] throws TologParserException {r = null;}: {m_rule = new TologRuleImpl(); } (rulehead) IMPLIES clauselist {m_rule.setRuleBody(m_currClauseList); } FULLSTOP { if (m_rules == null) m_rules = new ArrayList(); m_rules.add(m_rule); r = m_rule; } ; rulehead : name:NAME { m_rule.setName(name.getText()); addRule(name.getText(), m_rule); } LPAREN variable { m_rule.addHeadParameter(new Variable(m_varName)); } (COMMA variable { m_rule.addHeadParameter(new Variable(m_varName)); })* RPAREN ; query returns [TologQuery q] throws TologParserException { q = null; m_proj = new ProjectionImpl();}: (selectpart)? clauselist (orderpart)? (paging)? { if (m_pageStart < 0) throw new TologParserException("'offset' value must be an integer greater than or equal to 0."); if (m_pageLengthSet && (m_pageLength <= 0)) throw new TologParserException("'limit' value must be an integer greater than 0."); } QM { q = new TologQuery(m_currClauseList); if (m_proj != null) q.setProjection(m_proj); if (m_sorting != null) q.setSorting(m_sorting); if (m_pageStart > 0) q.setPageStart(m_pageStart); if (m_pageLength > 0) q.setPageLength(m_pageLength); } ; selectpart : "select" (STAR | (selectitem (COMMA selectitem)*)) "from" ; selectitem : variable { m_proj.addVariable(new Variable(m_varName)); } | count { m_proj.addCount(new Variable(m_varName)); } ; orderpart { m_sorting = new Sorting(); }: "order" "by" (variable { m_sorting.addSort(new Variable(m_varName));})+ ( ("asc" { m_sorting.setSortAscending(true);} ) | ("desc" { m_sorting.setSortAscending(false);} ) )? ; paging : "limit" l:INT { m_pageLength = Integer.parseInt(l.getText()); m_pageLengthSet = true; } ("offset" o:INT { m_pageStart = Integer.parseInt(o.getText());} ) ? ; count : "count" LPAREN variable RPAREN ; clauselist throws TologParserException: { m_currClauseList = new ClauseList(); } clause (COMMA clause)* ; clause throws TologParserException: orclause | notclause | (((variable|prefixedident) LPAREN) => predclause | opclause) ; predclause throws TologParserException: ( variable { if (m_log.isDebugEnabled()) m_log.debug("Predicate variable "+ m_varName); try { m_predicate = (Predicate)m_dynAssocPredicate.newInstance(); m_predicate.initialise(m_tm); m_predicateParams = new ArrayList(); m_predicateParams.add(new Variable(m_varName)); } catch (Exception ex) { throw new TologParserException("Unable to create a new dynamic association predicate from class " + m_dynAssocPredicate.getName() + ".", ex); } } | prefixedident { if (m_log.isDebugEnabled()) m_log.debug("Predicate Identifier: " + m_identifier); m_predicateParams = new ArrayList(); Class predClass = (Class)m_predicatesByID.get(m_identifier); if (predClass == null) { m_log.debug("No predicate class mapping found. Treating predicate as an association predicate."); try { m_predicate = (Predicate)m_dynAssocPredicate.newInstance(); m_predicate.initialise(m_tm); m_predicateParams.add(getObjectByIdent(m_identifier)); } catch (Exception ex) { throw new TologParserException("Unable to create a new dynamic association predicate from class " + m_dynAssocPredicate.getName() + ".", ex); } } else if (predClass.equals(TologRule.class)) { if (m_log.isDebugEnabled()) m_log.debug("Got reference to rule " + m_identifier); TologRule r = (TologRule)m_rulesByName.get(m_identifier); m_predicate = r.newInstance(); m_predicate.initialise(m_tm); } else { if (m_log.isDebugEnabled()) m_log.debug("Creating new " + predClass.getName() + " predicate instance."); try { m_predicate = (Predicate)predClass.newInstance(); m_predicate.initialise(m_tm); } catch (Exception ex) { throw new TologParserException("Error instantiating predicate class.", ex); } } } ) LPAREN (pair { m_predicateParams.add(m_param); } | URL { m_predicateParams.add(LT(0).getText()); }) (COMMA (pair { m_predicateParams.add(m_param); }) | URL { m_predicateParams.add(LT(0).getText());})* RPAREN { m_predicate.setParameters(m_predicateParams); m_currClauseList.addPredicate(m_predicate); } ; pair throws TologParserException: { if (m_dynAssocPredicate.isInstance(m_predicate)) { m_param = m_prp = new PlayerRoleVarPair(); } else { m_param = m_prp = null; } m_log.debug("START: pair"); } expr { if (m_refObject != null) { if (m_prp != null) { if (m_refObject instanceof Topic) { m_prp.setPlayerTopic((Topic)m_refObject); } else if (m_refObject instanceof Placeholder) { m_prp.setPlayerPlaceholder((Placeholder)m_refObject); } else { throw new TologParserException("Player part of a dynamic association parameter list must be either a Topic or a query parameter."); } } else { m_param = m_refObject; } } else if (m_varName != null) { if (m_prp != null) { m_prp.setPlayerVar(new Variable(m_varName)); } else { m_param = new Variable(m_varName); } } } (COLON expr { if (m_prp != null) { if (m_refObject != null) { if (m_refObject instanceof Topic) { m_prp.setRoleTopic((Topic)m_refObject); } else if (m_refObject instanceof Placeholder) { m_prp.setRolePlaceholder((Placeholder)m_refObject); } else { throw new TologParserException("Role type part must be either a Topic or a query parameter."); } } else if (m_varName != null) { m_prp.setRoleVar(new Variable(m_varName)); } } else { throw new TologParserException("Player:Role pairs are only allowed inside dynamic association predicates."); } } )? {m_log.debug("END: pair");} ; orclause throws TologParserException: { m_clauseStack.push(m_currClauseList); m_oc = new OrClause(); } LCURLY clauselist { m_oc.add(m_currClauseList); } (PIPE clauselist { m_oc.add(m_currClauseList); } )+ RCURLY { m_currClauseList = (ClauseList) m_clauseStack.pop(); m_currClauseList.addClause(m_oc); } ; notclause throws TologParserException: "not" LPAREN { m_clauseStack.push(m_currClauseList); m_nc = new NotClause(); } clauselist RPAREN { m_nc.setTest(m_currClauseList); m_currClauseList = (ClauseList)m_clauseStack.pop(); m_currClauseList.addClause(m_nc); } ; opclause throws TologParserException : { m_nec = new NEClause(); } (expr { m_nec.setLeft(m_refObject); m_nec.setLeftVar(m_varName); } "/=" expr { m_nec.setRight(m_refObject); m_nec.setRightVar(m_varName); }) { m_currClauseList.addClause(m_nec); } ; expr throws TologParserException : { m_varName = null; m_refObject = null; } (variable | ref) { m_log.debug("After expr: " + String.valueOf(m_varName) + "/" + String.valueOf(m_refObject)); } ; variable : {m_varName = null; } (DOLLAR NAME { m_varName = LT(0).getText(); }) ; ref throws TologParserException: { m_refObject = null; } prefixedident { m_refObject = getObjectByIdent(m_identifier); } ; prefixedident : (NAME DBLCOLON) => prefix:NAME DBLCOLON ref:NAME { m_log.debug("Got identifier '" + ref.getText() + "' with prefix '" + prefix.getText() + "'."); String exp = (String) m_prefixMap.get(prefix.getText()); m_identifier = (exp != null) ? exp + ref.getText() : prefix.getText() + ":" + ref.getText(); } | name:NAME { m_log.debug("Got identifier '" + name.getText() + "' with no prefix."); m_identifier = name.getText(); } | i:INDURL { m_identifier = i.getText(); } | a:ADDURL { m_identifier = a.getText(); } | s:SRCURL { m_identifier = s.getText(); } | o:OBJID { m_identifier = o.getText(); } | r:REPLACEABLE { m_identifier = r.getText(); } ; ident: name:NAME { m_identifier = name.getText(); } ; /* predname throws TologParserException : ident { m_log.debug("Predicate Identifier: " + m_identifier); m_predicateParams = new ArrayList(); Class predClass = (Class)m_predicatesByID.get(m_identifier); if (predClass == null) { m_log.debug("No predicate class mapping found. Treating predicate as an association predicate."); m_predicate = new AssociationPredicate(); m_predicateParams.add(getObjectByIdent(m_identifier)); } else if (predClass.equals(TologRule.class)) { m_log.debug("Got reference to rule " + m_identifier); m_predicate = m_rule.newInstance(); } else { m_log.debug("Creating new " + predClass.getName() + " predicate instance."); try { m_predicate = (Predicate)predClass.newInstance(); } catch (Exception ex) { throw new TologParserException("Error instantiating predicate class.", ex); } } } ; */ indicator: INDURL ; address: ADDURL ; srcloc: SRCURL ; /** * INTERNAL: Lexer for tolog syntax. */ class TologLexer extends Lexer; options { charVocabulary = '\1'..'\uFFFF'; k = 2; } INT : ('0'..'9')+ ; NAME : ('A'..'Z' | 'a'..'z' | '_') ('A'..'Z' | 'a'..'z' | '0'..'9' | '_' | '.' | '-')* ; URL : '"' (~('"' | '\n') | '\n' { newline(); } )* '"' ; INDURL : 'i' URL ; ADDURL : 'a' URL ; SRCURL : 's' URL ; OBJID : '@'NAME ; REPLACEABLE : '%' INT ; NE : "/="; IMPLIES : ":-"; DBLCOLON : "::"; WS : (' ' | '\t' | '\n' { newline(); } | '\r') { $setType(Token.SKIP); } ; COLON options { paraphrase = ":"; } : ':' ; COMMA options { paraphrase = ","; } : ',' ; PIPE options { paraphrase = "|"; } : '|' ; LPAREN options { paraphrase = "("; } : '(' ; RPAREN options { paraphrase = ")"; } : ')' ; LCURLY options { paraphrase = "{"; } : '{' ; RCURLY options { paraphrase = "}"; } : '}' ; DOLLAR options { paraphrase = "$"; } : '$' ; QM options { paraphrase = "?"; } : '?' ; FULLSTOP options { paraphrase = "."; } :'.' ; STAR options { paraphrase = "*"; } : '*' ; --- NEW FILE: TologQuery.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/parser/TologQuery.java,v 1.1 2005/03/06 17:29:06 lheuer Exp $ */ 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 (ka...@te...) */ 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)); } } /* * $Log: TologQuery.java,v $ * Revision 1.1 2005/03/06 17:29:06 lheuer * Initial tolog import * * Revision 1.9 2004/07/19 15:59:51 kal_ahmed * Query processing now initialises the input variable set correctly. * * Revision 1.8 2004/07/19 14:52:40 kal_ahmed * More fixes to processing of recursive rules. ClauseList now aborts when the input parameter list becomes empty. * * Revision 1.7 2004/06/20 14:12:30 kal_ahmed * Copied TologRsultsSet interface and TologFragmentBuilder implementation from org.tm4j.tolog to this package. * * Revision 1.6 2004/06/16 21:21:43 kal_ahmed * Tolog queries may now contain replaceable references specified in an Object array parameter to the QueryEvaluator at evaluation time. * * Revision 1.5 2004/06/13 19:44:30 kal_ahmed * Added a fix and test for handling recursive rules definitions. * * Revision 1.4 2004/06/09 20:20:30 kal_ahmed * Major reworking of the predicate interfaces and internal implementation of VariableSet to reduce the use of HashMaps. * * Revision 1.3 2004/06/07 20:31:33 kal_ahmed * Completed work on projection and sorting. Performed a bit more code reorganisation. Added DirectInstanceOfPredicate. * * Revision 1.2 2004/06/03 19:55:16 kal_ahmed * Created utils package to hold common utility classes for Tolog implementations. * * Revision 1.1 2004/06/03 19:47:22 kal_ahmed * Separated parser and parsed query representation classes into a sub-package. * * Revision 1.1 2004/05/30 22:08:25 kal_ahmed * Initial version of tolog 1.0 engine * */ --- NEW FILE: Variable.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/parser/Variable.java,v 1.1 2005/03/06 17:29:07 lheuer Exp $ */ package org.tmapiutils.query.tolog.parser; /** * * @author Kal Ahmed (ka...@te...) */ 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(); } } /* * $Log: Variable.java,v $ * Revision 1.1 2005/03/06 17:29:07 lheuer * Initial tolog import * * Revision 1.2 2004/06/03 19:55:16 kal_ahmed * Created utils package to hold common utility classes for Tolog implementations. * * Revision 1.1 2004/06/03 19:47:22 kal_ahmed * Separated parser and parsed query representation classes into a sub-package. * * Revision 1.1 2004/05/30 22:08:25 kal_ahmed * Initial version of tolog 1.0 engine * */ --- NEW FILE: Projection.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/parser/Projection.java,v 1.1 2005/03/06 17:29:06 lheuer Exp $ */ package org.tmapiutils.query.tolog.parser; import java.util.List; import org.tmapiutils.query.tolog.utils.VariableSet; /** * @author Kal * * Describe Projection here. */ 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(); } /* * $Log: Projection.java,v $ * Revision 1.1 2005/03/06 17:29:06 lheuer * Initial tolog import * * Revision 1.6 2004/06/09 21:12:19 kal_ahmed * Added standard source file header and footer. * */ --- NEW FILE: Sorting.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/parser/Sorting.java,v 1.1 2005/03/06 17:29:06 lheuer Exp $ */ 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 (ka...@te...) */ 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(); } } /* * $Log: Sorting.java,v $ * Revision 1.1 2005/03/06 17:29:06 lheuer * Initial tolog import * * Revision 1.4 2004/06/07 20:31:33 kal_ahmed * Completed work on projection and sorting. Performed a bit more code reorganisation. Added DirectInstanceOfPredicate. * * Revision 1.3 2004/06/03 20:04:56 kal_ahmed * Completed initial package restructuring. * * Revision 1.2 2004/06/03 19:55:16 kal_ahmed * Created utils package to hold common utility classes for Tolog implementations. * * Revision 1.1 2004/06/03 19:47:22 kal_ahmed * Separated parser and parsed query representation classes into a sub-package. * * Revision 1.1 2004/05/30 22:08:25 kal_ahmed * Initial version of tolog 1.0 engine * */ --- NEW FILE: TologRuleImpl.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/parser/TologRuleImpl.java,v 1.1 2005/03/06 17:29:07 lheuer Exp $ */ package org.tmapiutils.query.tolog.parser; import java.util.ArrayList; import java.util.Iterator; import java.util.List; /** * @author Kal * * Describe DefaultRuleImpl here. */ 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(); } } /* * $Log: TologRuleImpl.java,v $ * Revision 1.1 2005/03/06 17:29:07 lheuer * Initial tolog import * * Revision 1.3 2004/06/09 21:12:19 kal_ahmed * Added standard source file header and footer. * */ --- NEW FILE: TologRuleInstance.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/parser/TologRuleInstance.java,v 1.1 2005/03/06 17:29:07 lheuer Exp $ */ package org.tmapiutils.query.tolog.parser; /** * @author Kal * * Describe RuleInstance here. */ public interface TologRuleInstance extends Predicate { } /* * $Log: TologRuleInstance.java,v $ * Revision 1.1 2005/03/06 17:29:07 lheuer * Initial tolog import * * Revision 1.3 2004/06/09 21:12:19 kal_ahmed * Added standard source file header and footer. * */ --- NEW FILE: ProjectionImpl.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/parser/ProjectionImpl.java,v 1.1 2005/03/06 17:29:06 lheuer Exp $ */ 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 (ka...@te...) */ 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).getID()); } 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(); } } /* * $Log: ProjectionImpl.java,v $ * Revision 1.1 2005/03/06 17:29:06 lheuer * Initial tolog import * * Revision 1.3 2004/06/09 21:05:01 kal_ahmed * Added support for 'select * from' projection. * * Revision 1.2 2004/06/09 20:20:30 kal_ahmed * Major reworking of the predicate interfaces and internal implementation of VariableSet to reduce the use of HashMaps. * * Revision 1.1 2004/06/07 20:31:33 kal_ahmed * Completed work on projection and sorting. Performed a bit more code reorganisation. Added DirectInstanceOfPredicate. * * Revision 1.3 2004/06/03 20:04:56 kal_ahmed * Completed initial package restructuring. * * Revision 1.2 2004/06/03 19:55:16 kal_ahmed * Created utils package to hold common utility classes for Tolog implementations. * * Revision 1.1 2004/06/03 19:47:22 kal_ahmed * Separated parser and parsed query representation classes into a sub-package. * * Revision 1.1 2004/05/30 22:08:25 kal_ahmed * Initial version of tolog 1.0 engine * */ --- NEW FILE: Clause.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/parser/Clause.java,v 1.1 2005/03/06 17:29:06 lheuer Exp $ */ 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 (ka...@te...) */ public interface Clause { public void doReplacement(Object[] params) throws TologProcessingException; public VariableSet execute(VariableSet in, TologContext context) throws TologProcessingException; public List getVariables(); } /* * $Log: Clause.java,v $ * Revision 1.1 2005/03/06 17:29:06 lheuer * Initial tolog import * * Revision 1.6 2004/06/16 21:21:43 kal_ahmed * Tolog queries may now contain replaceable references specified in an Object array parameter to the QueryEvaluator at evaluation time. * * Revision 1.5 2004/06/13 19:44:30 kal_ahmed * Added a fix and test for handling recursive rules definitions. * * Revision 1.4 2004/06/09 20:20:30 kal_ahmed * Major reworking of the predicate interfaces and internal implementation of VariableSet to reduce the use of HashMaps. * * Revision 1.3 2004/06/03 20:04:56 kal_ahmed * Completed initial package restructuring. * * Revision 1.2 2004/06/03 19:55:16 kal_ahmed * Created utils package to hold common utility classes for Tolog implementations. * * Revision 1.1 2004/06/03 19:47:22 kal_ahmed * Separated parser and parsed query representation classes into a sub-package. * * Revision 1.1 2004/05/30 22:08:25 kal_ahmed * Initial version of tolog 1.0 engine * */ --- NEW FILE: OrClause.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/parser/OrClause.java,v 1.1 2005/03/06 17:29:06 lheuer Exp $ */ 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 (ka...@te...) */ 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); } } } /* * $Log: OrClause.java,v $ * Revision 1.1 2005/03/06 17:29:06 lheuer * Initial tolog import * * Revision 1.7 2004/07/16 13:51:36 kal_ahmed * Fixes for tolog engine handling of rules and rule-recursion. * * Revision 1.6 2004/06/16 21:21:43 kal_ahmed * Tolog queries may now contain replaceable references specified in an Object array parameter to the QueryEvaluator at evaluation time. * * Revision 1.5 2004/06/13 19:44:30 kal_ahmed * Added a fix and test for handling recursive rules definitions. * * Revision 1.4 2004/06/09 20:20:30 kal_ahmed * Major reworking of the predicate interfaces and internal implementation of VariableSet to reduce the use of HashMaps. * * Revision 1.3 2004/06/03 20:04:56 kal_ahmed * Completed initial package restructuring. * * Revision 1.2 2004/06/03 19:55:16 kal_ahmed * Created utils package to hold common utility classes for Tolog implementations. * * Revision 1.1 2004/06/03 19:47:22 kal_ahmed * Separated parser and parsed query representation classes into a sub-package. * * Revision 1.2 2004/06/02 19:22:13 kal_ahmed * Added support for parsing rules and including them in queries. * * Revision 1.1 2004/05/30 22:08:25 kal_ahmed * Initial version of tolog 1.0 engine * */ --- NEW FILE: Placeholder.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/parser/Placeholder.java,v 1.1 2005/03/06 17:29:06 lheuer Exp $ */ package org.tmapiutils.query.tolog.parser; import org.tmapiutils.query.tolog.TologParserException; import org.tmapiutils.query.tolog.TologProcessingException; /** * * @author Kal Ahmed (ka...@te...) */ public class Placeholder { private int m_ix; public Placeholder(int i) throws TologParserException { if (i >= 1) { m_ix = i; } else { throw new TologParserException("Invalid replaceable parameter. Parameters must be integer values greater than or equal to 1."); } } public int getIndex() { return m_ix; } /** * @param params * @return */ public Object getReplacement(Object[] params) throws TologProcessingException { if (m_ix <= params.length) { return params[m_ix - 1]; } else { throw new TologProcessingException("Insufficient parameters. No replacement found for reference %" + m_ix); } } public String toString() { return "%" + String.valueOf(m_ix); } } /* * $Log: Placeholder.java,v $ * Revision 1.1 2005/03/06 17:29:06 lheuer * Initial tolog import * * Revision 1.1 2004/06/20 15:17:41 kal_ahmed * Initial version * */ --- NEW FILE: Predicate.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/parser/Predicate.java,v 1.1 2005/03/06 17:29:06 lheuer Exp $ */ package org.tmapiutils.query.tolog.parser; import java.util.List; import org.tmapiutils.query.tolog.TologParserException; import org.tmapiutils.query.tolog.TologProcessingException; import org.tmapiutils.query.tolog.utils.TologContext; import org.tmapiutils.query.tolog.utils.VariableSet; import org.tmapi.core.TopicMap; /** * * @author Kal Ahmed (ka...@te...) */ public interface Predicate { public void initialise(TopicMap tm) throws TologParserException; public VariableSet matches(List params, TologContext context) throws TologProcessingException; public void setParameters(List params) throws TologParserException; public List getParameters(); } /* * $Log: Predicate.java,v $ * Revision 1.1 2005/03/06 17:29:06 lheuer * Initial tolog import * * Revision 1.7 2004/06/13 19:44:30 kal_ahmed * Added a fix and test for handling recursive rules definitions. * * Revision 1.6 2004/06/09 22:15:08 kal_ahmed * Fixed parser to disallow player:role pairs in predicates other than dynamic association predicates. Fixed initialisation of extension predicates. Added DirectInstanceOfPredicate extension to in-memory query evaluator. * * Revision 1.5 2004/06/09 20:20:30 kal_ahmed * Major reworking of the predicate interfaces and internal implementation of VariableSet to reduce the use of HashMaps. * * Revision 1.4 2004/06/07 20:31:27 kal_ahmed * Completed work on projection and sorting. Performed a bit more code reorganisation. Added DirectInstanceOfPredicate. * * Revision 1.3 2004/06/03 20:04:56 kal_ahmed * Completed initial package restructuring. * * Revision 1.2 2004/06/03 19:55:16 kal_ahmed * Created utils package to hold common utility classes for Tolog implementations. * * Revision 1.1 2004/06/03 19:47:22 kal_ahmed * Separated parser and parsed query representation classes into a sub-package. * * Revision 1.1 2004/05/30 22:08:25 kal_ahmed * Initial version of tolog 1.0 engine * */ --- NEW FILE: PlayerRoleVarPair.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/parser/PlayerRoleVarPair.java,v 1.1 2005/03/06 17:29:06 lheuer Exp $ */ package org.tmapiutils.query.tolog.parser; import org.tmapi.core.Topic; /** * * @author Kal Ahmed (ka...@te...) */ public class PlayerRoleVarPair extends PlayerRolePair { private Variable m_pVar; private Variable m_rVar; private Placeholder m_pPh; private Placeholder m_rPh; public PlayerRoleVarPair() { } public PlayerRoleVarPair(Variable playerVar, Variable roleVar) { m_pVar = playerVar; m_rVar = roleVar; } public PlayerRoleVarPair(Variable playerVar, Topic roleTopic) { m_pVar = playerVar; m_rTopic = roleTopic; } public PlayerRoleVarPair(Topic playerTopic, Variable roleVar) { m_pTopic = playerTopic; m_rVar = roleVar; } public PlayerRoleVarPair(Topic playerTopic, Topic roleTopic) { super(playerTopic, roleTopic); } public Variable getPlayerVar() { return m_pVar; } public Placeholder getPlayerPlaceholder() { return m_pPh; } public Variable getRoleVar() { return m_rVar; } public Placeholder getRolePlaceholder() { return m_rPh; } public boolean matches(PlayerRolePair prp) { boolean matches = true; if (m_pTopic != null) { matches = m_pTopic.equals(prp.m_pTopic); } if (matches && m_rTopic != null) { matches = m_rTopic.equals(prp.m_rTopic); } return matches; } public void setRoleVar(Variable var) { m_rPh = null; m_rVar = var; } public void setRolePlaceholder(Placeholder ph) { m_rVar = null; m_rPh = ph; } public void setRoleTopic(Topic t) { m_rTopic = t; } public void setPlayerVar(Variable var) { m_pVar = var; } public void setPlayerPlaceholder(Placeholder ph) { m_pVar = null; m_pPh = ph; } public void setPlayerTopic(Topic t) { m_pTopic = t; } public String toString() { StringBuffer sb = new StringBuffer(); if (m_pVar == null) { if (m_pPh == null) { sb.append(m_pTopic.getID()); } else { sb.append(m_pPh.toString()); } } else { sb.append(m_pVar.toString()); } if (m_rTopic != null) { sb.append(":"); sb.append(m_rTopic.getID()); } else if (m_rVar != null) { sb.append(":"); sb.append(m_rVar.getName()); } else if (m_rPh != null) { sb.append(":"); sb.append(m_rPh.toString()); } return sb.toString(); } } /* * $Log: PlayerRoleVarPair.java,v $ * Revision 1.1 2005/03/06 17:29:06 lheuer * Initial tolog import * * Revision 1.3 2004/06/16 21:21:43 kal_ahmed * Tolog queries may now contain replaceable references specified in an Object array parameter to the QueryEvaluator at evaluation time. * * Revision 1.2 2004/06/03 19:55:16 kal_ahmed * Created utils package to hold common utility classes for Tolog implementations. * * Revision 1.1 2004/06/03 19:47:22 kal_ahmed * Separated parser and parsed query representation classes into a sub-package. * * Revision 1.1 2004/05/30 22:08:25 kal_ahmed * Initial version of tolog 1.0 engine * */ --- NEW FILE: TologRule.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/parser/TologRule.java,v 1.1 2005/03/06 17:29:07 lheuer Exp $ */ package org.tmapiutils.query.tolog.parser; import java.util.List; /** * @author Kal * * Describe Rule here. */ public interface TologRule { public void setName(String name); public String getName(); public List getHeadParameters(); public void addHeadParameter(Variable param); public void setRuleBody(ClauseList body); public ClauseList getRuleBody(); public TologRuleInstance newInstance(); } /* * $Log: TologRule.java,v $ * Revision 1.1 2005/03/06 17:29:07 lheuer * Initial tolog import * * Revision 1.3 2004/06/09 21:12:19 kal_ahmed * Added standard source file header and footer. * */ --- NEW FILE: NotClause.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/parser/NotClause.java,v 1.1 2005/03/06 17:29:06 lheuer Exp $ */ 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 (ka...@te...) */ public class NotClause implements Clause { private Clause m_testClause; public void setTe... [truncated message content] |
From: Lars H. <lh...@us...> - 2005-03-06 17:28:56
|
Update of /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/memory In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25446/src/org/tmapiutils/query/tolog/memory Added Files: PreparedQueryImpl.java QueryEvaluatorImpl.java Log Message: Initial tolog import --- NEW FILE: PreparedQueryImpl.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/memory/PreparedQueryImpl.java,v 1.1 2005/03/06 17:28:46 lheuer Exp $ */ 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 * * Describe PreparedQueryImpl here. */ 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); } } /* * $Log: PreparedQueryImpl.java,v $ * Revision 1.1 2005/03/06 17:28:46 lheuer * Initial tolog import * * Revision 1.4 2004/06/20 14:12:30 kal_ahmed * Copied TologRsultsSet interface and TologFragmentBuilder implementation from org.tm4j.tolog to this package. * * Revision 1.3 2004/06/16 21:21:43 kal_ahmed * Tolog queries may now contain replaceable references specified in an Object array parameter to the QueryEvaluator at evaluation time. * * Revision 1.2 2004/06/09 21:12:18 kal_ahmed * Added standard source file header and footer. * */ --- NEW FILE: QueryEvaluatorImpl.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/memory/QueryEvaluatorImpl.java,v 1.1 2005/03/06 17:28:46 lheuer Exp $ */ 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 * * Describe QueryEvaluatorImpl here. */ 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; } } /* * $Log: QueryEvaluatorImpl.java,v $ * Revision 1.1 2005/03/06 17:28:46 lheuer * Initial tolog import * * Revision 1.12 2004/11/02 16:03:38 kal_ahmed * Fixed reported bug with processing external tolog modules. * * Revision 1.11 2004/08/17 14:55:28 kal_ahmed * Fixed naming of subject-locator and subject-identifier predicate implementations (Bug#1010670). * * Revision 1.10 2004/06/20 14:12:30 kal_ahmed * Copied TologRsultsSet interface and TologFragmentBuilder implementation from org.tm4j.tolog to this package. * * Revision 1.9 2004/06/16 21:21:43 kal_ahmed * Tolog queries may now contain replaceable references specified in an Object array parameter to the QueryEvaluator at evaluation time. * * Revision 1.8 2004/06/14 21:31:16 kal_ahmed * Added TopicNamePredicate to builtins. * * Revision 1.7 2004/06/13 19:44:30 kal_ahmed * Added a fix and test for handling recursive rules definitions. * * Revision 1.6 2004/06/13 17:17:59 kal_ahmed * Added registration of builtin predicates. Fixed rule expansion code to handle player/role pairs correctly. * * Revision 1.5 2004/06/10 17:09:34 kal_ahmed * Added reifies and instance-of predicates. * * Revision 1.4 2004/06/10 08:18:35 kal_ahmed * Added OccurrencePredicate to default extensions. * * Revision 1.3 2004/06/09 22:15:08 kal_ahmed * Fixed parser to disallow player:role pairs in predicates other than dynamic association predicates. Fixed initialisation of extension predicates. Added DirectInstanceOfPredicate extension to in-memory query evaluator. * * Revision 1.2 2004/06/09 21:12:18 kal_ahmed * Added standard source file header and footer. * */ |
From: Lars H. <lh...@us...> - 2005-03-06 17:27:45
|
Update of /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25046/src/org/tmapiutils/query/tolog Added Files: PreparedQuery.java QueryEvaluator.java QueryEvaluatorFactory.java TologFragmentBuilder.java TologFragmentBuilderException.java TologFragmentBuilderImpl.java TologParserException.java TologProcessingException.java TologResultsSet.java Log Message: Initial tolog import --- NEW FILE: QueryEvaluator.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* * $Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/QueryEvaluator.java,v 1.1 2005/03/06 17:27:33 lheuer Exp $ */ 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. */ 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(); } /* * $Log: QueryEvaluator.java,v $ * Revision 1.1 2005/03/06 17:27:33 lheuer * Initial tolog import * * Revision 1.8 2004/06/20 14:12:30 kal_ahmed * Copied TologRsultsSet interface and TologFragmentBuilder implementation from org.tm4j.tolog to this package. * * Revision 1.7 2004/06/16 21:21:42 kal_ahmed * Tolog queries may now contain replaceable references specified in an Object array parameter to the QueryEvaluator at evaluation time. * * Revision 1.6 2004/06/13 19:44:21 kal_ahmed * Added a fix and test for handling recursive rules definitions. * * Revision 1.5 2004/06/13 17:17:58 kal_ahmed * Added registration of builtin predicates. Fixed rule expansion code to handle player/role pairs correctly. * * Revision 1.4 2004/06/09 22:15:07 kal_ahmed * Fixed parser to disallow player:role pairs in predicates other than dynamic association predicates. Fixed initialisation of extension predicates. Added DirectInstanceOfPredicate extension to in-memory query evaluator. * * Revision 1.3 2004/06/03 19:55:16 kal_ahmed * Created utils package to hold common utility classes for Tolog implementations. * * Revision 1.2 2004/06/03 19:36:21 kal_ahmed * Added support for 'using' and 'import' directives to parser. * * Revision 1.1 2004/06/02 19:54:45 kal_ahmed * Initial proposal for high-level query interface. * */ --- NEW FILE: QueryEvaluatorFactory.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/QueryEvaluatorFactory.java,v 1.1 2005/03/06 17:27:33 lheuer Exp $ */ package org.tmapiutils.query.tolog; import org.tmapiutils.query.tolog.memory.QueryEvaluatorImpl; import org.tmapi.core.TopicMap; /** * @author Kal * * Describe QueryEvaluatorFactory here. */ public class QueryEvaluatorFactory { public static QueryEvaluator newQueryEvaluator(TopicMap tm) { QueryEvaluator qe = new QueryEvaluatorImpl(tm); return qe; } } /* * $Log: QueryEvaluatorFactory.java,v $ * Revision 1.1 2005/03/06 17:27:33 lheuer * Initial tolog import * * Revision 1.2 2004/06/09 21:12:18 kal_ahmed * Added standard source file header and footer. * */ --- NEW FILE: TologParserException.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/TologParserException.java,v 1.1 2005/03/06 17:27:33 lheuer Exp $ */ package org.tmapiutils.query.tolog; /** * * @author Kal Ahmed (ka...@te...) */ public class TologParserException extends Exception { public TologParserException(String msg) { super(msg); } public TologParserException(String msg, Throwable cause) { super(msg, cause); } } /* * $Log: TologParserException.java,v $ * Revision 1.1 2005/03/06 17:27:33 lheuer * Initial tolog import * * Revision 1.1 2004/05/30 22:08:25 kal_ahmed * Initial version of tolog 1.0 engine * */ --- NEW FILE: TologProcessingException.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/TologProcessingException.java,v 1.1 2005/03/06 17:27:33 lheuer Exp $ */ package org.tmapiutils.query.tolog; /** * * @author Kal Ahmed (ka...@te...) */ public class TologProcessingException extends Exception { public TologProcessingException(String msg) { super(msg); } public TologProcessingException(String msg, Throwable cause) { super(msg, cause); } } /* * $Log: TologProcessingException.java,v $ * Revision 1.1 2005/03/06 17:27:33 lheuer * Initial tolog import * * Revision 1.1 2004/05/30 22:08:25 kal_ahmed * Initial version of tolog 1.0 engine * */ --- NEW FILE: TologFragmentBuilderException.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. This software is licensed under a modified version of the Apache Software License. The full license text can be found at http://tm4j.org/LICENSE.txt */ /* * $Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/TologFragmentBuilderException.java,v 1.1 2005/03/06 17:27:33 lheuer Exp $ */ package org.tmapiutils.query.tolog; /** * Exception raised by the TologFragmentBuilder interface when exporting * a TologResultsSet object into a topic map fragment. */ 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; } } /* * $Log: TologFragmentBuilderException.java,v $ * Revision 1.1 2005/03/06 17:27:33 lheuer * Initial tolog import * * Revision 1.1 2004/06/20 14:12:30 kal_ahmed * Copied TologRsultsSet interface and TologFragmentBuilder implementation from org.tm4j.tolog to this package. * * Revision 1.3 2004/02/26 21:33:42 kal_ahmed * Updated license text and reformatted source with Jalopy. * * Revision 1.2 2003/08/31 15:08:39 kal_ahmed * Reformatted source code to Sun code style. * * Revision 1.1 2002/12/02 16:51:12 kal_ahmed * Initial version * */ --- NEW FILE: TologFragmentBuilderImpl.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. This software is licensed under a modified version of the Apache Software License. The full license text can be found at http://tm4j.org/LICENSE.txt */ /* * $Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/TologFragmentBuilderImpl.java,v 1.1 2005/03/06 17:27:33 lheuer Exp $ */ package org.tmapiutils.query.tolog; import org.tm4j.net.Locator; import org.tm4j.net.LocatorFactory; import org.tm4j.net.LocatorFactoryException; 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.getID()); 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.getID()); 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.getID()) == null) { Topic cp = m_frag.addTopic((Topic) row.get(i), 0); copiedRow.add(cp); } else { copiedRow.add((Topic) m_frag.getTopicMap() .getObjectByID(src.getID())); } } 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); } } } /* * $Log: TologFragmentBuilderImpl.java,v $ * Revision 1.1 2005/03/06 17:27:33 lheuer * Initial tolog import * * Revision 1.1 2004/06/20 14:12:30 kal_ahmed * Copied TologRsultsSet interface and TologFragmentBuilder implementation from org.tm4j.tolog to this package. * * Revision 1.6 2004/02/26 21:33:42 kal_ahmed * Updated license text and reformatted source with Jalopy. * * Revision 1.5 2003/08/31 15:08:39 kal_ahmed * Reformatted source code to Sun code style. * * Revision 1.4 2003/06/19 21:09:57 kal_ahmed * Updated factory methods to eliminate deprecation warnings. * * Revision 1.3 2003/05/01 15:51:56 kal_ahmed * Reorganised import statements. * * Revision 1.2 2002/12/13 21:30:09 kal_ahmed * Fixed Javadoc bugs * * Revision 1.1 2002/12/02 16:51:12 kal_ahmed * Initial version * */ --- NEW FILE: TologResultsSet.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. This software is licensed under a modified version of the Apache Software License. The full license text can be found at http://tm4j.org/LICENSE.txt */ /* * $Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/TologResultsSet.java,v 1.1 2005/03/06 17:27:33 lheuer Exp $ */ 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. */ 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); } /* * $Log: TologResultsSet.java,v $ * Revision 1.1 2005/03/06 17:27:33 lheuer * Initial tolog import * * Revision 1.1 2004/06/20 14:12:30 kal_ahmed * Copied TologRsultsSet interface and TologFragmentBuilder implementation from org.tm4j.tolog to this package. * * Revision 1.4 2004/02/26 21:33:42 kal_ahmed * Updated license text and reformatted source with Jalopy. * * Revision 1.3 2003/08/31 15:08:39 kal_ahmed * Reformatted source code to Sun code style. * * Revision 1.2 2002/05/06 11:53:43 kal_ahmed * Added header and log * */ --- NEW FILE: PreparedQuery.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. The license for this source code can be found in the file LICENSE.TXT with this distribution or at http://tm4j.org/LICENSE.txt */ /* *$Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/PreparedQuery.java,v 1.1 2005/03/06 17:27:33 lheuer Exp $ */ 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. */ 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; } /* * $Log: PreparedQuery.java,v $ * Revision 1.1 2005/03/06 17:27:33 lheuer * Initial tolog import * * Revision 1.4 2004/06/20 14:12:30 kal_ahmed * Copied TologRsultsSet interface and TologFragmentBuilder implementation from org.tm4j.tolog to this package. * * Revision 1.3 2004/06/16 21:21:42 kal_ahmed * Tolog queries may now contain replaceable references specified in an Object array parameter to the QueryEvaluator at evaluation time. * * Revision 1.2 2004/06/09 21:12:18 kal_ahmed * Added standard source file header and footer. * */ --- NEW FILE: TologFragmentBuilder.java --- /* Copyright (c) 2000-2004 The TM4J Project. All rights reserved. This software is licensed under a modified version of the Apache Software License. The full license text can be found at http://tm4j.org/LICENSE.txt */ /* * $Header: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/TologFragmentBuilder.java,v 1.1 2005/03/06 17:27:33 lheuer Exp $ */ package org.tmapiutils.query.tolog; import org.tmapi.core.utils.TopicMapFragment; /** * The interface for implementations which export a TologResultsSet into * a TopicMapFragment. */ 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-03-06 17:23:27
|
Update of /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24050/test Log Message: Directory /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/test added to the repository |