uima-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From twgo...@apache.org
Subject svn commit: r707049 - in /incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas: ConstraintFactory.java FSBooleanConstraint.java impl/BooleanConstraint.java impl/ConstraintFactoryImpl.java impl/FSBooleanConstraintImpl.java
Date Wed, 22 Oct 2008 11:58:39 GMT
Author: twgoetz
Date: Wed Oct 22 04:58:39 2008
New Revision: 707049

URL: http://svn.apache.org/viewvc?rev=707049&view=rev
Log:
Jira UIMA-1188: add boolean fs constraint.  Code contributed by Julien Nioche, see Jira issue.

https://issues.apache.org/jira/browse/UIMA-1188

Added:
    incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/FSBooleanConstraint.java
    incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/BooleanConstraint.java
    incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSBooleanConstraintImpl.java
Modified:
    incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/ConstraintFactory.java
    incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/ConstraintFactoryImpl.java

Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/ConstraintFactory.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/ConstraintFactory.java?rev=707049&r1=707048&r2=707049&view=diff
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/ConstraintFactory.java
(original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/ConstraintFactory.java
Wed Oct 22 04:58:39 2008
@@ -79,6 +79,14 @@
    * @return A new String constraint, completely unconstrained.
    */
   public abstract FSStringConstraint createStringConstraint();
+  
+  /**
+   * Create a new boolean constraint. A boolean constraint must be initialized after it's
created by
+   * adding one or more tests to it.
+   * 
+   * @return A new boolean constraint, completely unconstrained.
+   */
+  public abstract FSBooleanConstraint createBooleanConstraint();
 
   /**
    * Combine a constraint test with a path from a feature structure instance to the value
to be

Added: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/FSBooleanConstraint.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/FSBooleanConstraint.java?rev=707049&view=auto
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/FSBooleanConstraint.java
(added)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/FSBooleanConstraint.java
Wed Oct 22 04:58:39 2008
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.uima.cas;
+
+/**
+ * Interface for a boolean constraint. A boolean constraint contains a single condition,
either true
+ * or false. To set the condition, use 
+ * <p>
+ * To use the constraint, invoke its {@link #match(float)} method, passing the value to test.
You
+ * can also embed this test with a path specification, using the
+ * {@link org.apache.uima.cas.ConstraintFactory#embedConstraint(FeaturePath, FSConstraint)}
method,
+ * and use it to test feature structures, or combine it with other tests using the
+ * {@link org.apache.uima.cas.ConstraintFactory#and(FSMatchConstraint, FSMatchConstraint)}
and
+ * {@link org.apache.uima.cas.ConstraintFactory#or(FSMatchConstraint, FSMatchConstraint)}
methods.
+
+ */
+public interface FSBooleanConstraint extends FSConstraint {
+
+  /**
+   * Set the constraint.
+   * @param condition The condition that needs to be matched to satisfy the constraint.
+   */
+  public void eq(boolean condition);
+  
+  /**
+   * Check the condition.
+   * @param condition Value to compare with the condition.
+   * @return True if value and constraint are equal, false else.
+   */
+  public boolean match(boolean condition);
+}

Added: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/BooleanConstraint.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/BooleanConstraint.java?rev=707049&view=auto
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/BooleanConstraint.java
(added)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/BooleanConstraint.java
Wed Oct 22 04:58:39 2008
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.uima.cas.impl;
+
+import java.util.ArrayList;
+
+import org.apache.uima.cas.FSBooleanConstraint;
+import org.apache.uima.cas.FSMatchConstraint;
+import org.apache.uima.cas.Feature;
+import org.apache.uima.cas.FeatureStructure;
+
+/**
+ * Implementation of boolean match constraint.  See interface for documentation.
+ */
+public class BooleanConstraint extends PathConstraint implements FSMatchConstraint {
+
+  private final FSBooleanConstraint cons;
+  
+  @SuppressWarnings("unused")
+  private BooleanConstraint() {
+    this(null, null);
+  }
+  
+  BooleanConstraint(ArrayList<?> path, FSBooleanConstraint constraint) {
+    super(path);
+    this.cons = constraint;
+  }
+
+  public boolean match(FeatureStructure fs) {
+    final int max = this.featNames.size() - 1; // The last position in the
+    // path!
+    if (max < 0) {
+      // If the path is empty, we can't get a boolean, and therefore the
+      // constraint is not satisfied.
+      return false;
+    }
+    Feature feat;
+    for (int i = 0; i < max; i++) {
+      feat = fs.getType().getFeatureByBaseName((String) this.featNames.get(i));
+      if (feat == null) {
+        return false;
+      }
+      fs = fs.getFeatureValue(feat);
+    }
+    feat = fs.getType().getFeatureByBaseName((String) this.featNames.get(max));
+    if (feat == null) {
+      return false;
+    }
+    return this.cons.match(fs.getBooleanValue(feat));
+  }
+
+}

Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/ConstraintFactoryImpl.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/ConstraintFactoryImpl.java?rev=707049&r1=707048&r2=707049&view=diff
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/ConstraintFactoryImpl.java
(original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/ConstraintFactoryImpl.java
Wed Oct 22 04:58:39 2008
@@ -22,6 +22,7 @@
 import java.util.ArrayList;
 
 import org.apache.uima.cas.ConstraintFactory;
+import org.apache.uima.cas.FSBooleanConstraint;
 import org.apache.uima.cas.FSConstraint;
 import org.apache.uima.cas.FSFloatConstraint;
 import org.apache.uima.cas.FSIntConstraint;
@@ -37,60 +38,70 @@
  */
 public class ConstraintFactoryImpl extends ConstraintFactory {
 
-  public FSTypeConstraint createTypeConstraint() {
-    return new FSTypeConstraintImpl();
-  }
-
-  public FSIntConstraint createIntConstraint() {
-    return new FSIntConstraintImpl();
-  }
-
-  public FSFloatConstraint createFloatConstraint() {
-    return new FSFloatConstraintImpl();
-  }
-
-  public FSStringConstraint createStringConstraint() {
-    return new FSStringConstraintImpl();
-  }
-
-  public FSMatchConstraint embedConstraint(FeaturePath featPath, FSConstraint constraint)
{
-    ArrayList path = new ArrayList();
-    for (int i = 0; i < featPath.size(); i++) {
-      path.add(featPath.getFeature(i).getShortName());
-    }
-    if (constraint instanceof FSMatchConstraint) {
-      return new EmbeddedConstraint(path, constraint);
-    } else if (constraint instanceof FSIntConstraint) {
-      return new IntConstraint(path, (FSIntConstraint) constraint);
-    } else if (constraint instanceof FSFloatConstraint) {
-      return new FloatConstraint(path, (FSFloatConstraint) constraint);
-    } else if (constraint instanceof FSStringConstraint) {
-      return new StringConstraint(path, (FSStringConstraint) constraint);
-    } else {
-      return null;
-    }
-  }
-
-  public FSMatchConstraint embedConstraint(ArrayList path, FSConstraint constraint) {
-    if (constraint instanceof FSMatchConstraint) {
-      return new EmbeddedConstraint(path, constraint);
-    } else if (constraint instanceof FSIntConstraint) {
-      return new IntConstraint(path, (FSIntConstraint) constraint);
-    } else if (constraint instanceof FSFloatConstraint) {
-      return new FloatConstraint(path, (FSFloatConstraint) constraint);
-    } else if (constraint instanceof FSStringConstraint) {
-      return new StringConstraint(path, (FSStringConstraint) constraint);
-    } else {
-      return null;
-    }
-  }
-
-  public FSMatchConstraint and(FSMatchConstraint c1, FSMatchConstraint c2) {
-    return new ConjunctiveConstraint(c1, c2);
-  }
-
-  public FSMatchConstraint or(FSMatchConstraint c1, FSMatchConstraint c2) {
-    return new DisjunctiveConstraint(c1, c2);
-  }
+	public FSTypeConstraint createTypeConstraint() {
+		return new FSTypeConstraintImpl();
+	}
+
+	public FSIntConstraint createIntConstraint() {
+		return new FSIntConstraintImpl();
+	}
+
+	public FSFloatConstraint createFloatConstraint() {
+		return new FSFloatConstraintImpl();
+	}
+
+	public FSStringConstraint createStringConstraint() {
+		return new FSStringConstraintImpl();
+	}
+
+	public FSBooleanConstraint createBooleanConstraint() {
+		return new FSBooleanConstraintImpl();
+	}
+
+	public FSMatchConstraint embedConstraint(FeaturePath featPath,
+			FSConstraint constraint) {
+		ArrayList path = new ArrayList();
+		for (int i = 0; i < featPath.size(); i++) {
+			path.add(featPath.getFeature(i).getShortName());
+		}
+		if (constraint instanceof FSMatchConstraint) {
+			return new EmbeddedConstraint(path, constraint);
+		} else if (constraint instanceof FSIntConstraint) {
+			return new IntConstraint(path, (FSIntConstraint) constraint);
+		} else if (constraint instanceof FSFloatConstraint) {
+			return new FloatConstraint(path, (FSFloatConstraint) constraint);
+		} else if (constraint instanceof FSStringConstraint) {
+			return new StringConstraint(path, (FSStringConstraint) constraint);
+		} else if (constraint instanceof FSBooleanConstraint) {
+			return new BooleanConstraint(path, (FSBooleanConstraint) constraint);
+		} else {
+			return null;
+		}
+	}
+
+	public FSMatchConstraint embedConstraint(ArrayList path,
+			FSConstraint constraint) {
+		if (constraint instanceof FSMatchConstraint) {
+			return new EmbeddedConstraint(path, constraint);
+		} else if (constraint instanceof FSIntConstraint) {
+			return new IntConstraint(path, (FSIntConstraint) constraint);
+		} else if (constraint instanceof FSFloatConstraint) {
+			return new FloatConstraint(path, (FSFloatConstraint) constraint);
+		} else if (constraint instanceof FSStringConstraint) {
+			return new StringConstraint(path, (FSStringConstraint) constraint);
+		} else if (constraint instanceof FSBooleanConstraint) {
+			return new BooleanConstraint(path, (FSBooleanConstraint) constraint);
+		} else {
+			return null;
+		}
+	}
+
+	public FSMatchConstraint and(FSMatchConstraint c1, FSMatchConstraint c2) {
+		return new ConjunctiveConstraint(c1, c2);
+	}
+
+	public FSMatchConstraint or(FSMatchConstraint c1, FSMatchConstraint c2) {
+		return new DisjunctiveConstraint(c1, c2);
+	}
 
 }

Added: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSBooleanConstraintImpl.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSBooleanConstraintImpl.java?rev=707049&view=auto
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSBooleanConstraintImpl.java
(added)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSBooleanConstraintImpl.java
Wed Oct 22 04:58:39 2008
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.uima.cas.impl;
+
+import org.apache.uima.cas.FSBooleanConstraint;
+
+/**
+ * See interface for documentation.
+ */
+public class FSBooleanConstraintImpl implements FSBooleanConstraint {
+
+  private boolean condition = true;
+  
+  /**
+   * Default constructor.
+   */
+  public FSBooleanConstraintImpl() {
+    super();
+  }
+
+  /* (non-Javadoc)
+   * @see org.apache.uima.cas.FSBooleanConstraint#eq(boolean)
+   */
+  public void eq(boolean cond) {
+    this.condition = cond;
+  }
+  
+  /* (non-Javadoc)
+   * @see org.apache.uima.cas.FSBooleanConstraint#match(boolean)
+   */
+  public boolean match(boolean cond) {
+    return (this.condition == cond);
+  }
+
+}



Mime
View raw message