Update of /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30131/src/org/tmapiutils/query/tolog/predicates Modified Files: AssociationPredicate.java AssociationRolePredicate.java BaseLocatorPredicate.java DirectInstanceOfPredicate.java DynamicAssociationPredicate.java InstanceOfPredicate.java OccurrencePredicate.java PredicateBase.java ReifiesPredicate.java ResourcePredicate.java RolePlayerPredicate.java ScopePredicate.java SourceLocatorsPredicate.java SubjectIdentifierPredicate.java SubjectLocatorPredicate.java TopicMapPredicate.java TopicNamePredicate.java TopicPredicate.java TypePredicate.java ValueLikePredicate.java ValuePredicate.java VariantPredicate.java Log Message: Tabs -> Whitespaces Index: TopicPredicate.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/TopicPredicate.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TopicPredicate.java 8 Mar 2005 12:33:57 -0000 1.2 --- TopicPredicate.java 8 Jul 2005 16:03:20 -0000 1.3 *************** *** 1,72 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. All rights reserved. ! * ! * Licensed under the Apache License, Version 2.0 (the "License"); ! * you may not use this file except in compliance with the License. ! * You may obtain a copy of the License at ! * ! * http://www.apache.org/licenses/LICENSE-2.0 ! * ! * Unless required by applicable law or agreed to in writing, software ! * distributed under the License is distributed on an "AS IS" BASIS, ! * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ! * See the License for the specific language governing permissions and ! * limitations under the License. ! */ ! ! package org.tmapiutils.query.tolog.predicates; ! ! import java.util.Iterator; ! import java.util.List; ! ! import org.tmapiutils.query.tolog.TologProcessingException; ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! import org.tmapi.core.Topic; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class TopicPredicate extends PredicateBase { ! ! public static final String PREDICATE_NAME = "topic"; ! private static final ParameterInfo[] PARAM_INFO = new ParameterInfo[] { ! new ParameterInfo(true, Object.class) ! }; ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getParamInfo() ! */ ! public ParameterInfo[] getParamInfo() { ! return PARAM_INFO; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getPredicateName() ! */ ! public String getPredicateName() { ! return PREDICATE_NAME; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.parser.Predicate#matches(java.util.List) ! */ ! public VariableSet matches(List params) throws TologProcessingException { ! VariableSet ret = new VariableSet(); ! initialiseResultsSet(ret); ! Object p = params.get(0); ! if (p instanceof Variable) { ! Iterator it = getTopicMap().getTopics().iterator(); ! while (it.hasNext()) { ! addResultsRow(ret, new Object[] {it.next()}); ! } ! } else if (p instanceof Topic) { ! addResultsRow(ret, new Object[] {p}); ! } ! return ret; ! } ! ! } --- 1,72 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. All rights reserved. ! * ! * Licensed under the Apache License, Version 2.0 (the "License"); ! * you may not use this file except in compliance with the License. ! * You may obtain a copy of the License at ! * ! * http://www.apache.org/licenses/LICENSE-2.0 ! * ! * Unless required by applicable law or agreed to in writing, software ! * distributed under the License is distributed on an "AS IS" BASIS, ! * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ! * See the License for the specific language governing permissions and ! * limitations under the License. ! */ ! ! package org.tmapiutils.query.tolog.predicates; ! ! import java.util.Iterator; ! import java.util.List; ! ! import org.tmapiutils.query.tolog.TologProcessingException; ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! import org.tmapi.core.Topic; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class TopicPredicate extends PredicateBase { ! ! public static final String PREDICATE_NAME = "topic"; ! private static final ParameterInfo[] PARAM_INFO = new ParameterInfo[] { ! new ParameterInfo(true, Object.class) ! }; ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getParamInfo() ! */ ! public ParameterInfo[] getParamInfo() { ! return PARAM_INFO; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getPredicateName() ! */ ! public String getPredicateName() { ! return PREDICATE_NAME; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.parser.Predicate#matches(java.util.List) ! */ ! public VariableSet matches(List params) throws TologProcessingException { ! VariableSet ret = new VariableSet(); ! initialiseResultsSet(ret); ! Object p = params.get(0); ! if (p instanceof Variable) { ! Iterator it = getTopicMap().getTopics().iterator(); ! while (it.hasNext()) { ! addResultsRow(ret, new Object[] {it.next()}); ! } ! } else if (p instanceof Topic) { ! addResultsRow(ret, new Object[] {p}); ! } ! return ret; ! } ! ! } Index: AssociationPredicate.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/AssociationPredicate.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** AssociationPredicate.java 9 Mar 2005 12:40:19 -0000 1.3 --- AssociationPredicate.java 8 Jul 2005 16:03:20 -0000 1.4 *************** *** 1,74 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. All rights reserved. ! * ! * Licensed under the Apache License, Version 2.0 (the "License"); ! * you may not use this file except in compliance with the License. ! * You may obtain a copy of the License at ! * ! * http://www.apache.org/licenses/LICENSE-2.0 ! * ! * Unless required by applicable law or agreed to in writing, software ! * distributed under the License is distributed on an "AS IS" BASIS, ! * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ! * See the License for the specific language governing permissions and ! * limitations under the License. ! */ ! ! package org.tmapiutils.query.tolog.predicates; ! ! import java.util.Iterator; ! import java.util.List; ! ! import org.tmapiutils.query.tolog.TologProcessingException; ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! // TMAPI ! import org.tmapi.core.Association; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class AssociationPredicate extends PredicateBase { ! ! public static final String PREDICATE_NAME = "association"; ! private static final ParameterInfo[] PARAM_INFO = new ParameterInfo[] { ! new ParameterInfo(true, Object.class) ! }; ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getParamInfo() ! */ ! public ParameterInfo[] getParamInfo() { ! return PARAM_INFO; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getPredicateName() ! */ ! public String getPredicateName() { ! return PREDICATE_NAME; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.parser.Predicate#matches(java.util.List) ! */ ! public VariableSet matches(List params) throws TologProcessingException { ! VariableSet ret = new VariableSet(); ! initialiseResultsSet(ret); ! Object p = params.get(0); ! if (p instanceof Variable) { ! Iterator it = getTopicMap().getAssociations().iterator(); ! while (it.hasNext()) { ! addResultsRow(ret, new Object[] {it.next()}); ! } ! } else if (p instanceof Association) { ! addResultsRow(ret, new Object[] {p}); ! } ! return ret; ! } ! ! } ! --- 1,74 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. All rights reserved. ! * ! * Licensed under the Apache License, Version 2.0 (the "License"); ! * you may not use this file except in compliance with the License. ! * You may obtain a copy of the License at ! * ! * http://www.apache.org/licenses/LICENSE-2.0 ! * ! * Unless required by applicable law or agreed to in writing, software ! * distributed under the License is distributed on an "AS IS" BASIS, ! * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ! * See the License for the specific language governing permissions and ! * limitations under the License. ! */ ! ! package org.tmapiutils.query.tolog.predicates; ! ! import java.util.Iterator; ! import java.util.List; ! ! import org.tmapiutils.query.tolog.TologProcessingException; ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! // TMAPI ! import org.tmapi.core.Association; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class AssociationPredicate extends PredicateBase { ! ! public static final String PREDICATE_NAME = "association"; ! private static final ParameterInfo[] PARAM_INFO = new ParameterInfo[] { ! new ParameterInfo(true, Object.class) ! }; ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getParamInfo() ! */ ! public ParameterInfo[] getParamInfo() { ! return PARAM_INFO; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getPredicateName() ! */ ! public String getPredicateName() { ! return PREDICATE_NAME; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.parser.Predicate#matches(java.util.List) ! */ ! public VariableSet matches(List params) throws TologProcessingException { ! VariableSet ret = new VariableSet(); ! initialiseResultsSet(ret); ! Object p = params.get(0); ! if (p instanceof Variable) { ! Iterator it = getTopicMap().getAssociations().iterator(); ! while (it.hasNext()) { ! addResultsRow(ret, new Object[] {it.next()}); ! } ! } else if (p instanceof Association) { ! addResultsRow(ret, new Object[] {p}); ! } ! return ret; ! } ! ! } ! Index: TopicMapPredicate.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/TopicMapPredicate.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** TopicMapPredicate.java 9 Mar 2005 12:40:19 -0000 1.4 --- TopicMapPredicate.java 8 Jul 2005 16:03:20 -0000 1.5 *************** *** 1,72 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. All rights reserved. ! * ! * Licensed under the Apache License, Version 2.0 (the "License"); ! * you may not use this file except in compliance with the License. ! * You may obtain a copy of the License at ! * ! * http://www.apache.org/licenses/LICENSE-2.0 ! * ! * Unless required by applicable law or agreed to in writing, software ! * distributed under the License is distributed on an "AS IS" BASIS, ! * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ! * See the License for the specific language governing permissions and ! * limitations under the License. ! */ ! ! package org.tmapiutils.query.tolog.predicates; ! ! import java.util.List; ! ! import org.tmapiutils.query.tolog.TologProcessingException; ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! // TMAPI ! import org.tmapi.core.TopicMap; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class TopicMapPredicate extends PredicateBase { ! ! public static final String PREDICATE_NAME = "topicmap"; ! private static final ParameterInfo [] PARAM_INFO = new ParameterInfo [] { ! new ParameterInfo(true) ! }; ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getParamInfo() ! */ ! public ParameterInfo[] getParamInfo() { ! return PARAM_INFO; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getPredicateName() ! */ ! public String getPredicateName() { ! return PREDICATE_NAME; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.parser.Predicate#matches(java.util.List) ! */ ! public VariableSet matches(List params) throws TologProcessingException { ! VariableSet ret = new VariableSet(); ! initialiseResultsSet(ret); ! if (params.get(0) instanceof Variable) { ! addResultsRow(ret, new Object[] { getTopicMap()}); ! } else if (params.get(0) instanceof TopicMap) { ! TopicMap topicmap = (TopicMap)params.get(0); ! if (getTopicMap().equals(topicmap)) { ! addResultsRow(ret, new Object[] { topicmap }); ! } ! } ! return ret; ! } ! ! } ! --- 1,72 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. All rights reserved. ! * ! * Licensed under the Apache License, Version 2.0 (the "License"); ! * you may not use this file except in compliance with the License. ! * You may obtain a copy of the License at ! * ! * http://www.apache.org/licenses/LICENSE-2.0 ! * ! * Unless required by applicable law or agreed to in writing, software ! * distributed under the License is distributed on an "AS IS" BASIS, ! * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ! * See the License for the specific language governing permissions and ! * limitations under the License. ! */ ! ! package org.tmapiutils.query.tolog.predicates; ! ! import java.util.List; ! ! import org.tmapiutils.query.tolog.TologProcessingException; ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! // TMAPI ! import org.tmapi.core.TopicMap; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class TopicMapPredicate extends PredicateBase { ! ! public static final String PREDICATE_NAME = "topicmap"; ! private static final ParameterInfo [] PARAM_INFO = new ParameterInfo [] { ! new ParameterInfo(true) ! }; ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getParamInfo() ! */ ! public ParameterInfo[] getParamInfo() { ! return PARAM_INFO; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getPredicateName() ! */ ! public String getPredicateName() { ! return PREDICATE_NAME; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.parser.Predicate#matches(java.util.List) ! */ ! public VariableSet matches(List params) throws TologProcessingException { ! VariableSet ret = new VariableSet(); ! initialiseResultsSet(ret); ! if (params.get(0) instanceof Variable) { ! addResultsRow(ret, new Object[] { getTopicMap()}); ! } else if (params.get(0) instanceof TopicMap) { ! TopicMap topicmap = (TopicMap)params.get(0); ! if (getTopicMap().equals(topicmap)) { ! addResultsRow(ret, new Object[] { topicmap }); ! } ! } ! return ret; ! } ! ! } ! Index: ValuePredicate.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/ValuePredicate.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ValuePredicate.java 9 Mar 2005 12:40:19 -0000 1.5 --- ValuePredicate.java 8 Jul 2005 16:03:20 -0000 1.6 *************** *** 1,226 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. All rights reserved. ! * ! * Licensed under the Apache License, Version 2.0 (the "License"); ! * you may not use this file except in compliance with the License. ! * You may obtain a copy of the License at ! * ! * http://www.apache.org/licenses/LICENSE-2.0 ! * ! * Unless required by applicable law or agreed to in writing, software ! * distributed under the License is distributed on an "AS IS" BASIS, ! * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ! * See the License for the specific language governing permissions and ! * limitations under the License. ! */ ! ! package org.tmapiutils.query.tolog.predicates; ! ! import java.util.ArrayList; ! import java.util.Iterator; ! import java.util.List; ! ! import org.tmapiutils.query.tolog.TologParserException; ! import org.tmapiutils.query.tolog.TologProcessingException; ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! // TMAPI ! import org.tmapi.core.TopicMapObject; ! import org.tmapi.core.TopicMap; ! import org.tmapi.core.Topic; ! import org.tmapi.core.Occurrence; ! import org.tmapi.core.TopicName; ! import org.tmapi.core.Variant; ! import org.tmapi.core.TMAPIException; ! import org.tmapi.index.core.TopicNamesIndex; ! import org.tmapi.index.core.OccurrencesIndex; ! import org.tmapi.index.core.VariantsIndex; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class ValuePredicate extends PredicateBase { ! ! private OccurrencesIndex _occIdx; ! private TopicNamesIndex _tnIdx; ! private VariantsIndex _varIdx; ! ! public static final String PREDICATE_NAME = "value"; ! private static final ParameterInfo[] PARAM_INFO = new ParameterInfo[] { ! new ParameterInfo(true), ! new ParameterInfo(true) ! }; ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getParamInfo() ! */ ! public ParameterInfo[] getParamInfo() { ! return PARAM_INFO; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getPredicateName() ! */ ! public String getPredicateName() { ! return PREDICATE_NAME; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.parser.Predicate#matches(java.util.List) ! */ ! public VariableSet matches(List params) throws TologProcessingException { ! Object obj = params.get(0); ! Object val = params.get(1); ! VariableSet ret = new VariableSet(); ! initialiseResultsSet(ret); ! if ((obj instanceof TopicMapObject) && (val instanceof Variable)) { ! matchValue((TopicMapObject)obj, ret); ! } else if ((obj instanceof Variable) && (val instanceof String)) { ! matchObject((String)val, ret); ! } else if ((obj instanceof TopicMapObject) && (val instanceof String)) { ! closedMatch((TopicMapObject)obj, (String)val, ret); ! } else if ((obj instanceof Variable) && (val instanceof Variable)) { ! openMatch(ret); ! } ! return ret; ! } ! ! ! private String getValue(TopicMapObject tmObj) { ! String value = null; ! if (tmObj instanceof Occurrence) { ! value = ((Occurrence) tmObj).getValue(); ! } ! else if (tmObj instanceof TopicName) { ! value = ((TopicName) tmObj).getValue(); ! } ! else if (tmObj instanceof Variant) { ! value = ((Variant) tmObj).getValue(); ! } ! return value; ! } ! ! /** ! * @param object ! * @param ret ! */ ! private void matchValue(TopicMapObject object, VariableSet ret) throws TologProcessingException { ! ! String value = getValue(object); ! if (value != null) { ! addResultsRow(ret, new Object[] {object, value}); ! } ! } ! ! /** ! * @param string ! * @param ret ! */ ! private void matchObject(String data, VariableSet ret) throws TologProcessingException ! { ! try { ! _occIdx.open(); ! if (!_occIdx.getFlags().isAutoUpdated()) { ! _occIdx.reindex(); ! } ! _tnIdx.open(); ! if (!_tnIdx.getFlags().isAutoUpdated()) { ! _tnIdx.reindex(); ! } ! _varIdx.open(); ! if (!_varIdx.getFlags().isAutoUpdated()) { ! _varIdx.reindex(); ! } ! } ! catch (TMAPIException ex) { ! throw new TologProcessingException("Error initialising indexes for " + PREDICATE_NAME, ex); ! } ! for (Iterator it = _occIdx.getOccurrencesByValue(data).iterator(); it.hasNext();) { ! addResultsRow(ret, new Object[] {it.next(), data}); ! } ! for (Iterator it = _tnIdx.getTopicNamesByValue(data).iterator(); it.hasNext();) { ! addResultsRow(ret, new Object[] { it.next(), data }); ! } ! for (Iterator it = _varIdx.getVariantsByValue(data).iterator(); it.hasNext();) { ! addResultsRow(ret, new Object[] { it.next(), data }); ! } ! } ! ! /** ! * @param object ! * @param string ! * @param ret ! */ ! private void closedMatch(TopicMapObject object, String data, VariableSet ret) throws TologProcessingException { ! ! String value = getValue(object); ! if ((value != null) && value.equals(data)) { ! addResultsRow(ret, new Object[] { object, data }); ! } ! } ! ! /** ! * @param ret ! */ ! private void openMatch(VariableSet ret) throws TologProcessingException { ! ValuesExtractor vx = new ValuesExtractor(ret); ! for (Iterator it = getTopicMap().getTopics().iterator(); it.hasNext();) { ! vx.extractValues((Topic)it.next()); ! } ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.parser.Predicate#initialise(org.tmapi.core.TopicMap) ! */ ! public void initialise(TopicMap tm) throws TologParserException { ! super.initialise(tm); ! try { ! _occIdx = (OccurrencesIndex) tm.getHelperObject(OccurrencesIndex.class); ! _varIdx = (VariantsIndex) tm.getHelperObject(VariantsIndex.class); ! _tnIdx = (TopicNamesIndex) tm.getHelperObject(TopicNamesIndex.class); ! } catch (TMAPIException ex) { ! throw new TologParserException("Error initialising indexes for " + PREDICATE_NAME, ex); ! } ! } ! ! private class ValuesExtractor { ! ! private VariableSet m_vs; ! ! public ValuesExtractor(VariableSet vs) { ! m_vs = vs; ! } ! ! /* (non-Javadoc) ! * @see uk.co.jezuk.mango.UnaryFunction#fn(java.lang.Object) ! */ ! public void extractValues(Topic t) throws TologProcessingException { ! ArrayList ret = new ArrayList(); ! for (Iterator it = t.getTopicNames().iterator(); it.hasNext(); ) { ! TopicName bn = (TopicName)it.next(); ! addResultsRow(m_vs, new Object[] {bn, bn.getValue()}); ! addVariants(bn); ! } ! for (Iterator it = t.getOccurrences().iterator(); it.hasNext();) { ! Occurrence o = (Occurrence)it.next(); ! if (o.getValue() != null) { ! addResultsRow(m_vs, new Object[] { o, o.getValue() }); ! } ! } ! } ! ! private void addVariants(TopicName topicname) throws TologProcessingException { ! for (Iterator it = topicname.getVariants().iterator(); it.hasNext();) { ! Variant variant = (Variant) it.next(); ! String value = variant.getValue(); ! if (value != null) { ! addResultsRow(m_vs, new Object[] { variant, value }); ! } ! } ! } ! } ! } ! --- 1,226 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. All rights reserved. ! * ! * Licensed under the Apache License, Version 2.0 (the "License"); ! * you may not use this file except in compliance with the License. ! * You may obtain a copy of the License at ! * ! * http://www.apache.org/licenses/LICENSE-2.0 ! * ! * Unless required by applicable law or agreed to in writing, software ! * distributed under the License is distributed on an "AS IS" BASIS, ! * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ! * See the License for the specific language governing permissions and ! * limitations under the License. ! */ ! ! package org.tmapiutils.query.tolog.predicates; ! ! import java.util.ArrayList; ! import java.util.Iterator; ! import java.util.List; ! ! import org.tmapiutils.query.tolog.TologParserException; ! import org.tmapiutils.query.tolog.TologProcessingException; ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! // TMAPI ! import org.tmapi.core.TopicMapObject; ! import org.tmapi.core.TopicMap; ! import org.tmapi.core.Topic; ! import org.tmapi.core.Occurrence; ! import org.tmapi.core.TopicName; ! import org.tmapi.core.Variant; ! import org.tmapi.core.TMAPIException; ! import org.tmapi.index.core.TopicNamesIndex; ! import org.tmapi.index.core.OccurrencesIndex; ! import org.tmapi.index.core.VariantsIndex; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class ValuePredicate extends PredicateBase { ! ! private OccurrencesIndex _occIdx; ! private TopicNamesIndex _tnIdx; ! private VariantsIndex _varIdx; ! ! public static final String PREDICATE_NAME = "value"; ! private static final ParameterInfo[] PARAM_INFO = new ParameterInfo[] { ! new ParameterInfo(true), ! new ParameterInfo(true) ! }; ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getParamInfo() ! */ ! public ParameterInfo[] getParamInfo() { ! return PARAM_INFO; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getPredicateName() ! */ ! public String getPredicateName() { ! return PREDICATE_NAME; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.parser.Predicate#matches(java.util.List) ! */ ! public VariableSet matches(List params) throws TologProcessingException { ! Object obj = params.get(0); ! Object val = params.get(1); ! VariableSet ret = new VariableSet(); ! initialiseResultsSet(ret); ! if ((obj instanceof TopicMapObject) && (val instanceof Variable)) { ! matchValue((TopicMapObject)obj, ret); ! } else if ((obj instanceof Variable) && (val instanceof String)) { ! matchObject((String)val, ret); ! } else if ((obj instanceof TopicMapObject) && (val instanceof String)) { ! closedMatch((TopicMapObject)obj, (String)val, ret); ! } else if ((obj instanceof Variable) && (val instanceof Variable)) { ! openMatch(ret); ! } ! return ret; ! } ! ! ! private String getValue(TopicMapObject tmObj) { ! String value = null; ! if (tmObj instanceof Occurrence) { ! value = ((Occurrence) tmObj).getValue(); ! } ! else if (tmObj instanceof TopicName) { ! value = ((TopicName) tmObj).getValue(); ! } ! else if (tmObj instanceof Variant) { ! value = ((Variant) tmObj).getValue(); ! } ! return value; ! } ! ! /** ! * @param object ! * @param ret ! */ ! private void matchValue(TopicMapObject object, VariableSet ret) throws TologProcessingException { ! ! String value = getValue(object); ! if (value != null) { ! addResultsRow(ret, new Object[] {object, value}); ! } ! } ! ! /** ! * @param string ! * @param ret ! */ ! private void matchObject(String data, VariableSet ret) throws TologProcessingException ! { ! try { ! _occIdx.open(); ! if (!_occIdx.getFlags().isAutoUpdated()) { ! _occIdx.reindex(); ! } ! _tnIdx.open(); ! if (!_tnIdx.getFlags().isAutoUpdated()) { ! _tnIdx.reindex(); ! } ! _varIdx.open(); ! if (!_varIdx.getFlags().isAutoUpdated()) { ! _varIdx.reindex(); ! } ! } ! catch (TMAPIException ex) { ! throw new TologProcessingException("Error initialising indexes for " + PREDICATE_NAME, ex); ! } ! for (Iterator it = _occIdx.getOccurrencesByValue(data).iterator(); it.hasNext();) { ! addResultsRow(ret, new Object[] {it.next(), data}); ! } ! for (Iterator it = _tnIdx.getTopicNamesByValue(data).iterator(); it.hasNext();) { ! addResultsRow(ret, new Object[] { it.next(), data }); ! } ! for (Iterator it = _varIdx.getVariantsByValue(data).iterator(); it.hasNext();) { ! addResultsRow(ret, new Object[] { it.next(), data }); ! } ! } ! ! /** ! * @param object ! * @param string ! * @param ret ! */ ! private void closedMatch(TopicMapObject object, String data, VariableSet ret) throws TologProcessingException { ! ! String value = getValue(object); ! if ((value != null) && value.equals(data)) { ! addResultsRow(ret, new Object[] { object, data }); ! } ! } ! ! /** ! * @param ret ! */ ! private void openMatch(VariableSet ret) throws TologProcessingException { ! ValuesExtractor vx = new ValuesExtractor(ret); ! for (Iterator it = getTopicMap().getTopics().iterator(); it.hasNext();) { ! vx.extractValues((Topic)it.next()); ! } ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.parser.Predicate#initialise(org.tmapi.core.TopicMap) ! */ ! public void initialise(TopicMap tm) throws TologParserException { ! super.initialise(tm); ! try { ! _occIdx = (OccurrencesIndex) tm.getHelperObject(OccurrencesIndex.class); ! _varIdx = (VariantsIndex) tm.getHelperObject(VariantsIndex.class); ! _tnIdx = (TopicNamesIndex) tm.getHelperObject(TopicNamesIndex.class); ! } catch (TMAPIException ex) { ! throw new TologParserException("Error initialising indexes for " + PREDICATE_NAME, ex); ! } ! } ! ! private class ValuesExtractor { ! ! private VariableSet m_vs; ! ! public ValuesExtractor(VariableSet vs) { ! m_vs = vs; ! } ! ! /* (non-Javadoc) ! * @see uk.co.jezuk.mango.UnaryFunction#fn(java.lang.Object) ! */ ! public void extractValues(Topic t) throws TologProcessingException { ! ArrayList ret = new ArrayList(); ! for (Iterator it = t.getTopicNames().iterator(); it.hasNext(); ) { ! TopicName bn = (TopicName)it.next(); ! addResultsRow(m_vs, new Object[] {bn, bn.getValue()}); ! addVariants(bn); ! } ! for (Iterator it = t.getOccurrences().iterator(); it.hasNext();) { ! Occurrence o = (Occurrence)it.next(); ! if (o.getValue() != null) { ! addResultsRow(m_vs, new Object[] { o, o.getValue() }); ! } ! } ! } ! ! private void addVariants(TopicName topicname) throws TologProcessingException { ! for (Iterator it = topicname.getVariants().iterator(); it.hasNext();) { ! Variant variant = (Variant) it.next(); ! String value = variant.getValue(); ! if (value != null) { ! addResultsRow(m_vs, new Object[] { variant, value }); ! } ! } ! } ! } ! } ! Index: ScopePredicate.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/ScopePredicate.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ScopePredicate.java 9 Mar 2005 12:40:19 -0000 1.4 --- ScopePredicate.java 8 Jul 2005 16:03:20 -0000 1.5 *************** *** 1,143 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. All rights reserved. ! * ! * Licensed under the Apache License, Version 2.0 (the "License"); ! * you may not use this file except in compliance with the License. ! * You may obtain a copy of the License at ! * ! * http://www.apache.org/licenses/LICENSE-2.0 ! * ! * Unless required by applicable law or agreed to in writing, software ! * distributed under the License is distributed on an "AS IS" BASIS, ! * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ! * See the License for the specific language governing permissions and ! * limitations under the License. ! */ ! ! package org.tmapiutils.query.tolog.predicates; ! ! import java.util.Iterator; ! import java.util.List; ! ! import org.tmapiutils.query.tolog.TologParserException; ! import org.tmapiutils.query.tolog.TologProcessingException; ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! ! import org.tmapiutils.utils.IndexUtils; ! // TMAPI ! import org.tmapi.core.TopicMap; ! import org.tmapi.core.ScopedObject; ! import org.tmapi.core.Topic; ! import org.tmapi.core.TMAPIException; ! import org.tmapi.index.core.ScopedObjectsIndex; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class ScopePredicate extends PredicateBase { ! ! private ScopedObjectsIndex _scopeIdx; ! public static final String PREDICATE_NAME = "scope"; ! private static final ParameterInfo[] PARAM_INFO = new ParameterInfo[]{ ! new ParameterInfo(true), ! new ParameterInfo(true) ! }; ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getParamInfo() ! */ ! public ParameterInfo[] getParamInfo() { ! return PARAM_INFO; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getPredicateName() ! */ ! public String getPredicateName() { ! return PREDICATE_NAME; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.parser.Predicate#matches(java.util.List) ! */ ! public VariableSet matches(List params) throws TologProcessingException { ! Object scoped = params.get(0); ! Object theme = params.get(1); ! VariableSet ret = new VariableSet(); ! initialiseResultsSet(ret); ! if ((scoped instanceof ScopedObject) && (theme instanceof Variable)) { ! matchThemes((ScopedObject)scoped, ret); ! } else if ((scoped instanceof Variable) && (theme instanceof Topic)) { ! matchScopedObjects((Topic)theme, ret); ! } else if ((scoped instanceof ScopedObject) && (theme instanceof Topic)) { ! closedMatch((ScopedObject)scoped, (Topic)theme, ret); ! } else if ((scoped instanceof Variable) && (theme instanceof Variable)) { ! openMatch(ret); ! } ! return ret; ! } ! ! /** ! * @param ret ! */ ! private void openMatch(VariableSet ret) throws TologProcessingException { ! IndexUtils.updateIndex(_scopeIdx); ! for (Iterator themes = _scopeIdx.getScopingTopics().iterator(); themes.hasNext();){ ! Topic topic = (Topic) themes.next(); ! for (Iterator scoped = _scopeIdx.getScopedObjectsByScopingTopic(topic).iterator(); scoped.hasNext();) { ! addResultsRow(ret, new Object[] {scoped.next(), topic}); ! } ! } ! } ! ! /** ! * @param object ! * @param topic ! * @param ret ! */ ! private void closedMatch(ScopedObject scoped, Topic topic, VariableSet ret) throws TologProcessingException { ! for (Iterator it = scoped.getScope().iterator(); it.hasNext();) { ! if (it.next().equals(topic)) { ! addResultsRow(ret, new Object[] {scoped, topic}); ! } ! } ! } ! ! /** ! * @param topic ! * @param ret ! */ ! private void matchScopedObjects(Topic topic, VariableSet ret) throws TologProcessingException { ! IndexUtils.updateIndex(_scopeIdx); ! for (Iterator it = _scopeIdx.getScopedObjectsByScopingTopic(topic).iterator(); it.hasNext();) { ! addResultsRow(ret, new Object[] {it.next(), topic}); ! } ! } ! ! /** ! * @param object ! * @param ret ! */ ! private void matchThemes(ScopedObject scoped, VariableSet ret) throws TologProcessingException { ! for (Iterator it = scoped.getScope().iterator(); it.hasNext();) { ! addResultsRow(ret, new Object[] { scoped, it.next()}); ! } ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.parser.Predicate#initialise(org.tmapi.core.TopicMap) ! */ ! public void initialise(TopicMap tm) throws TologParserException { ! super.initialise(tm); ! try { ! _scopeIdx = (ScopedObjectsIndex) tm.getHelperObject(ScopedObjectsIndex.class); ! } catch (TMAPIException ex) { ! throw new TologParserException("Unable to initialise indexes for " + PREDICATE_NAME, ex); ! } ! } ! ! } --- 1,143 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. All rights reserved. ! * ! * Licensed under the Apache License, Version 2.0 (the "License"); ! * you may not use this file except in compliance with the License. ! * You may obtain a copy of the License at ! * ! * http://www.apache.org/licenses/LICENSE-2.0 ! * ! * Unless required by applicable law or agreed to in writing, software ! * distributed under the License is distributed on an "AS IS" BASIS, ! * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ! * See the License for the specific language governing permissions and ! * limitations under the License. ! */ ! ! package org.tmapiutils.query.tolog.predicates; ! ! import java.util.Iterator; ! import java.util.List; ! ! import org.tmapiutils.query.tolog.TologParserException; ! import org.tmapiutils.query.tolog.TologProcessingException; ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! ! import org.tmapiutils.utils.IndexUtils; ! // TMAPI ! import org.tmapi.core.TopicMap; ! import org.tmapi.core.ScopedObject; ! import org.tmapi.core.Topic; ! import org.tmapi.core.TMAPIException; ! import org.tmapi.index.core.ScopedObjectsIndex; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class ScopePredicate extends PredicateBase { ! ! private ScopedObjectsIndex _scopeIdx; ! public static final String PREDICATE_NAME = "scope"; ! private static final ParameterInfo[] PARAM_INFO = new ParameterInfo[]{ ! new ParameterInfo(true), ! new ParameterInfo(true) ! }; ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getParamInfo() ! */ ! public ParameterInfo[] getParamInfo() { ! return PARAM_INFO; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getPredicateName() ! */ ! public String getPredicateName() { ! return PREDICATE_NAME; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.parser.Predicate#matches(java.util.List) ! */ ! public VariableSet matches(List params) throws TologProcessingException { ! Object scoped = params.get(0); ! Object theme = params.get(1); ! VariableSet ret = new VariableSet(); ! initialiseResultsSet(ret); ! if ((scoped instanceof ScopedObject) && (theme instanceof Variable)) { ! matchThemes((ScopedObject)scoped, ret); ! } else if ((scoped instanceof Variable) && (theme instanceof Topic)) { ! matchScopedObjects((Topic)theme, ret); ! } else if ((scoped instanceof ScopedObject) && (theme instanceof Topic)) { ! closedMatch((ScopedObject)scoped, (Topic)theme, ret); ! } else if ((scoped instanceof Variable) && (theme instanceof Variable)) { ! openMatch(ret); ! } ! return ret; ! } ! ! /** ! * @param ret ! */ ! private void openMatch(VariableSet ret) throws TologProcessingException { ! IndexUtils.updateIndex(_scopeIdx); ! for (Iterator themes = _scopeIdx.getScopingTopics().iterator(); themes.hasNext();){ ! Topic topic = (Topic) themes.next(); ! for (Iterator scoped = _scopeIdx.getScopedObjectsByScopingTopic(topic).iterator(); scoped.hasNext();) { ! addResultsRow(ret, new Object[] {scoped.next(), topic}); ! } ! } ! } ! ! /** ! * @param object ! * @param topic ! * @param ret ! */ ! private void closedMatch(ScopedObject scoped, Topic topic, VariableSet ret) throws TologProcessingException { ! for (Iterator it = scoped.getScope().iterator(); it.hasNext();) { ! if (it.next().equals(topic)) { ! addResultsRow(ret, new Object[] {scoped, topic}); ! } ! } ! } ! ! /** ! * @param topic ! * @param ret ! */ ! private void matchScopedObjects(Topic topic, VariableSet ret) throws TologProcessingException { ! IndexUtils.updateIndex(_scopeIdx); ! for (Iterator it = _scopeIdx.getScopedObjectsByScopingTopic(topic).iterator(); it.hasNext();) { ! addResultsRow(ret, new Object[] {it.next(), topic}); ! } ! } ! ! /** ! * @param object ! * @param ret ! */ ! private void matchThemes(ScopedObject scoped, VariableSet ret) throws TologProcessingException { ! for (Iterator it = scoped.getScope().iterator(); it.hasNext();) { ! addResultsRow(ret, new Object[] { scoped, it.next()}); ! } ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.parser.Predicate#initialise(org.tmapi.core.TopicMap) ! */ ! public void initialise(TopicMap tm) throws TologParserException { ! super.initialise(tm); ! try { ! _scopeIdx = (ScopedObjectsIndex) tm.getHelperObject(ScopedObjectsIndex.class); ! } catch (TMAPIException ex) { ! throw new TologParserException("Unable to initialise indexes for " + PREDICATE_NAME, ex); ! } ! } ! ! } Index: AssociationRolePredicate.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/AssociationRolePredicate.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** AssociationRolePredicate.java 8 Mar 2005 12:33:56 -0000 1.4 --- AssociationRolePredicate.java 8 Jul 2005 16:03:20 -0000 1.5 *************** *** 1,115 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. All rights reserved. ! * ! * Licensed under the Apache License, Version 2.0 (the "License"); ! * you may not use this file except in compliance with the License. ! * You may obtain a copy of the License at ! * ! * http://www.apache.org/licenses/LICENSE-2.0 ! * ! * Unless required by applicable law or agreed to in writing, software ! * distributed under the License is distributed on an "AS IS" BASIS, ! * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ! * See the License for the specific language governing permissions and ! * limitations under the License. ! */ ! ! package org.tmapiutils.query.tolog.predicates; ! ! import java.util.Iterator; ! import java.util.List; ! ! import org.tmapiutils.query.tolog.TologProcessingException; ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! // TMAPI ! import org.tmapi.core.Association; ! import org.tmapi.core.AssociationRole; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class AssociationRolePredicate extends PredicateBase { ! ! public static final String PREDICATE_NAME = "association-role"; ! private static final ParameterInfo[] PARAM_INFO = new ParameterInfo[] { ! new ParameterInfo(true, Object.class), ! new ParameterInfo(true, Object.class) ! }; ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getParamInfo() ! */ ! public ParameterInfo[] getParamInfo() { ! return PARAM_INFO; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getPredicateName() ! */ ! public String getPredicateName() { ! return PREDICATE_NAME; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.parser.Predicate#matches(java.util.List) ! */ ! public VariableSet matches(List params) throws TologProcessingException { ! Object assoc = params.get(0); ! Object role = params.get(1); ! VariableSet ret = new VariableSet(); ! initialiseResultsSet(ret); ! ! if ((assoc instanceof Association) && (role instanceof Variable)) { ! matchRoles((Association)assoc, ret); ! } else if ((assoc instanceof Variable) && (role instanceof AssociationRole)) { ! addResultsRow(ret, new Object[] {((AssociationRole)role).getAssociation(), role}); ! } else if ((assoc instanceof Variable) && (role instanceof Variable)) { ! openMatch(ret); ! } else if ((assoc instanceof Association) && (role instanceof AssociationRole)) { ! closedMatch((Association)assoc, (AssociationRole)role, ret); ! } ! return ret; ! } ! ! /** ! * @param association ! * @param member ! * @param ret ! */ ! private void closedMatch(Association association, AssociationRole role, VariableSet ret) throws TologProcessingException { ! if (role.getAssociation().equals(association)) { ! addResultsRow(ret, new Object[] {association, role}); ! } ! } ! ! /** ! * @param ret ! */ ! private void openMatch(VariableSet ret) throws TologProcessingException { ! Iterator it = getTopicMap().getAssociations().iterator(); ! while (it.hasNext()) { ! Association assoc = (Association)it.next(); ! Iterator roles = assoc.getAssociationRoles().iterator(); ! while (roles.hasNext()) { ! addResultsRow(ret, new Object[] {assoc, roles.next()}); ! } ! } ! } ! ! /** ! * @param association ! * @param ret ! */ ! private void matchRoles(Association association, VariableSet ret) throws TologProcessingException { ! Iterator it = association.getAssociationRoles().iterator(); ! while (it.hasNext()) { ! addResultsRow(ret, new Object[] {association, it.next()}); ! } ! } ! ! } ! --- 1,115 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. All rights reserved. ! * ! * Licensed under the Apache License, Version 2.0 (the "License"); ! * you may not use this file except in compliance with the License. ! * You may obtain a copy of the License at ! * ! * http://www.apache.org/licenses/LICENSE-2.0 ! * ! * Unless required by applicable law or agreed to in writing, software ! * distributed under the License is distributed on an "AS IS" BASIS, ! * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ! * See the License for the specific language governing permissions and ! * limitations under the License. ! */ ! ! package org.tmapiutils.query.tolog.predicates; ! ! import java.util.Iterator; ! import java.util.List; ! ! import org.tmapiutils.query.tolog.TologProcessingException; ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! // TMAPI ! import org.tmapi.core.Association; ! import org.tmapi.core.AssociationRole; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class AssociationRolePredicate extends PredicateBase { ! ! public static final String PREDICATE_NAME = "association-role"; ! private static final ParameterInfo[] PARAM_INFO = new ParameterInfo[] { ! new ParameterInfo(true, Object.class), ! new ParameterInfo(true, Object.class) ! }; ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getParamInfo() ! */ ! public ParameterInfo[] getParamInfo() { ! return PARAM_INFO; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getPredicateName() ! */ ! public String getPredicateName() { ! return PREDICATE_NAME; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.parser.Predicate#matches(java.util.List) ! */ ! public VariableSet matches(List params) throws TologProcessingException { ! Object assoc = params.get(0); ! Object role = params.get(1); ! VariableSet ret = new VariableSet(); ! initialiseResultsSet(ret); ! ! if ((assoc instanceof Association) && (role instanceof Variable)) { ! matchRoles((Association)assoc, ret); ! } else if ((assoc instanceof Variable) && (role instanceof AssociationRole)) { ! addResultsRow(ret, new Object[] {((AssociationRole)role).getAssociation(), role}); ! } else if ((assoc instanceof Variable) && (role instanceof Variable)) { ! openMatch(ret); ! } else if ((assoc instanceof Association) && (role instanceof AssociationRole)) { ! closedMatch((Association)assoc, (AssociationRole)role, ret); ! } ! return ret; ! } ! ! /** ! * @param association ! * @param member ! * @param ret ! */ ! private void closedMatch(Association association, AssociationRole role, VariableSet ret) throws TologProcessingException { ! if (role.getAssociation().equals(association)) { ! addResultsRow(ret, new Object[] {association, role}); ! } ! } ! ! /** ! * @param ret ! */ ! private void openMatch(VariableSet ret) throws TologProcessingException { ! Iterator it = getTopicMap().getAssociations().iterator(); ! while (it.hasNext()) { ! Association assoc = (Association)it.next(); ! Iterator roles = assoc.getAssociationRoles().iterator(); ! while (roles.hasNext()) { ! addResultsRow(ret, new Object[] {assoc, roles.next()}); ! } ! } ! } ! ! /** ! * @param association ! * @param ret ! */ ! private void matchRoles(Association association, VariableSet ret) throws TologProcessingException { ! Iterator it = association.getAssociationRoles().iterator(); ! while (it.hasNext()) { ! addResultsRow(ret, new Object[] {association, it.next()}); ! } ! } ! ! } ! Index: SubjectLocatorPredicate.java =================================================================== RCS file: /cvsroot/tmapi-utils/tmapi-utils/src/org/tmapiutils/query/tolog/predicates/SubjectLocatorPredicate.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** SubjectLocatorPredicate.java 8 Mar 2005 12:33:57 -0000 1.4 --- SubjectLocatorPredicate.java 8 Jul 2005 16:03:20 -0000 1.5 *************** *** 1,142 **** ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. All rights reserved. ! * ! * Licensed under the Apache License, Version 2.0 (the "License"); ! * you may not use this file except in compliance with the License. ! * You may obtain a copy of the License at ! * ! * http://www.apache.org/licenses/LICENSE-2.0 ! * ! * Unless required by applicable law or agreed to in writing, software ! * distributed under the License is distributed on an "AS IS" BASIS, ! * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ! * See the License for the specific language governing permissions and ! * limitations under the License. ! */ ! ! package org.tmapiutils.query.tolog.predicates; ! ! import java.util.Iterator; ! import java.util.List; ! ! import org.tmapiutils.query.tolog.TologParserException; ! import org.tmapiutils.query.tolog.TologProcessingException; ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! ! import org.tmapiutils.utils.IndexUtils; ! // TMAPI ! import org.tmapi.core.Locator; ! import org.tmapi.core.TopicMap; ! import org.tmapi.core.Topic; ! import org.tmapi.core.TMAPIException; ! import org.tmapi.index.core.TopicsIndex; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class SubjectLocatorPredicate extends PredicateBase { ! ! private TopicsIndex _topicsIdx; ! public static final String PREDICATE_NAME = "subject-locator"; ! private static final ParameterInfo[] PARAM_INFO = new ParameterInfo[] { ! new ParameterInfo(true), ! new ParameterInfo(true) ! }; ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getParamInfo() ! */ ! public ParameterInfo[] getParamInfo() { ! return PARAM_INFO; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getPredicateName() ! */ ! public String getPredicateName() { ! return PREDICATE_NAME; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.parser.Predicate#matches(java.util.List) ! */ ! public VariableSet matches(List params) throws TologProcessingException { ! Object topic = params.get(0); ! Object loc = params.get(1); ! VariableSet ret = new VariableSet(); ! initialiseResultsSet(ret); ! ! if ((topic instanceof Topic) && (loc instanceof Variable)) { ! matchSubjectLocator((Topic)topic, ret); ! } else if ((topic instanceof Variable) && (loc instanceof Locator)) { ! matchTopic((Locator)loc, ret); ! } else if ((topic instanceof Topic) && (loc instanceof Locator)) { ! closedMatch((Topic)topic, (Locator)loc, ret); ! } else if ((topic instanceof Variable) && (loc instanceof Variable)) { ! openMatch(ret); ! } ! return ret; ! } ! ! /** ! * @param ret ! */ ! private void openMatch(VariableSet ret) throws TologProcessingException { ! for (Iterator it = getTopicMap().getTopics().iterator(); it.hasNext();) { ! Topic topic = (Topic)it.next(); ! for (Iterator locIter = topic.getSubjectLocators().iterator(); locIter.hasNext();) { ! addResultsRow(ret, new Object[] { topic, locIter.next()}); ! } ! } ! } ! ! /** ! * @param topic ! * @param locator ! * @param ret ! */ ! private void closedMatch(Topic topic, Locator locator, VariableSet ret) throws TologProcessingException { ! if (topic.getSubjectLocators().contains(locator)) { ! addResultsRow(ret, new Object[] { topic, locator}); ! } ! } ! ! /** ! * @param locator ! * @param ret ! */ ! private void matchTopic(Locator locator, VariableSet ret) throws TologProcessingException { ! IndexUtils.updateIndex(_topicsIdx); ! Topic topic = _topicsIdx.getTopicBySubjectLocator(locator); ! if (topic != null) { ! addResultsRow(ret, new Object[] { topic, locator }); ! } ! } ! ! /** ! * @param topic ! * @param ret ! */ ! private void matchSubjectLocator(Topic topic, VariableSet ret) throws TologProcessingException { ! for (Iterator iter = topic.getSubjectLocators().iterator(); iter.hasNext();) { ! addResultsRow(ret, new Object[] { topic, iter.next()}); ! } ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.parser.Predicate#initialise(org.tmapi.core.TopicMap) ! */ ! public void initialise(TopicMap tm) throws TologParserException { ! super.initialise(tm); ! try { ! _topicsIdx = (TopicsIndex) tm.getHelperObject(TopicsIndex.class); ! } catch (TMAPIException ex) { ! throw new TologParserException("Unable to initialise indexes for " + PREDICATE_NAME, ex); ! } ! } ! ! } --- 1,142 ---- ! /* ! * Copyright 2005 TMAPI Utils / Kal Ahmed, Lars Heuer ! * Copyright (c) 2000-2004 The TM4J Project. All rights reserved. ! * ! * Licensed under the Apache License, Version 2.0 (the "License"); ! * you may not use this file except in compliance with the License. ! * You may obtain a copy of the License at ! * ! * http://www.apache.org/licenses/LICENSE-2.0 ! * ! * Unless required by applicable law or agreed to in writing, software ! * distributed under the License is distributed on an "AS IS" BASIS, ! * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ! * See the License for the specific language governing permissions and ! * limitations under the License. ! */ ! ! package org.tmapiutils.query.tolog.predicates; ! ! import java.util.Iterator; ! import java.util.List; ! ! import org.tmapiutils.query.tolog.TologParserException; ! import org.tmapiutils.query.tolog.TologProcessingException; ! import org.tmapiutils.query.tolog.parser.Variable; ! import org.tmapiutils.query.tolog.utils.VariableSet; ! ! import org.tmapiutils.utils.IndexUtils; ! // TMAPI ! import org.tmapi.core.Locator; ! import org.tmapi.core.TopicMap; ! import org.tmapi.core.Topic; ! import org.tmapi.core.TMAPIException; ! import org.tmapi.index.core.TopicsIndex; ! ! /** ! * ! * @author Kal Ahmed (kal[at]techquila.com) ! * @author Lars Heuer (heuer[at]semagia.com) ! */ ! public class SubjectLocatorPredicate extends PredicateBase { ! ! private TopicsIndex _topicsIdx; ! public static final String PREDICATE_NAME = "subject-locator"; ! private static final ParameterInfo[] PARAM_INFO = new ParameterInfo[] { ! new ParameterInfo(true), ! new ParameterInfo(true) ! }; ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getParamInfo() ! */ ! public ParameterInfo[] getParamInfo() { ! return PARAM_INFO; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.predicates.PredicateBase#getPredicateName() ! */ ! public String getPredicateName() { ! return PREDICATE_NAME; ! } ! ! /* (non-Javadoc) ! * @see org.tmapiutils.query.tolog.parser.Predicate#matches(java.util.List) ! */ ! public VariableSet matches(List params) throws TologProcessingException { ! Object topic = params.get(0); ! Object loc = params.get(1); ! VariableSet ret = new VariableSet(); ! initialiseResultsSet(ret); ! ! if ((topic instanceof Topic) && (loc instanceof Variable)) { ! matchSubjectLocator((Topic)topic, ret); ! } else if ((topic instanceof Variable) && (loc instanceof Locator)) { ! matchTopic((Locator)loc, ret); ! } else if ((topic instanceof Topic) && (loc i... [truncated message content] |