public static Map<String, String> match(
      Table<Integer, String, String> table, Map<String, FieldValue> values) {
    Set<Integer> rowKeys = table.rowKeySet();

    rows:
    for (Integer rowKey : rowKeys) {
      Map<String, String> row = table.row(rowKey);

      // A table row contains a certain number of input columns, plus an output column
      if (values.size() < (row.size() - 1)) {
        continue rows;
      }

      Collection<Map.Entry<String, FieldValue>> entries = values.entrySet();
      for (Map.Entry<String, FieldValue> entry : entries) {
        String key = entry.getKey();
        FieldValue value = entry.getValue();

        String rowValue = row.get(key);
        if (rowValue == null) {
          continue rows;
        }

        boolean equals = value.equalsString(rowValue);
        if (!equals) {
          continue rows;
        }
      }

      return row;
    }

    return null;
  }
Esempio n. 2
0
 public void toXML(XMLWriter writer) throws IOException {
   writer.setDefaultFormat();
   writer.enterNamespace(STARTS.NAMESPACE_NAME);
   writer.printStartElement("sqrdocument", true);
   writer.printAttribute("version", version);
   writer.printStartElementClose();
   writer.indent();
   writer.printEntireElement("rawscore", rawScore);
   for (Iterator it = sources.iterator(); it.hasNext(); ) {
     LSPSource source = (LSPSource) it.next();
     source.toXML(writer);
   }
   for (Iterator it = fieldValues.iterator(); it.hasNext(); ) {
     FieldValue fv = (FieldValue) it.next();
     fv.toXML(writer);
   }
   writer.printStartElement("term-stats-list");
   for (Iterator it = termStats.iterator(); it.hasNext(); ) {
     TermStat ts = (TermStat) it.next();
     ts.toXML(writer);
   }
   writer.printEndElement("term-stats-list");
   writer.printEntireElement("docsize", docSize);
   writer.printEntireElement("doccount", docCount);
   writer.unindent();
   writer.printEndElement("sqrdocument");
   writer.exitNamespace();
 }
Esempio n. 3
0
    @Override
    public FieldValue evaluate(List<FieldValue> values) {
      StorelessUnivariateStatistic statistic = createStatistic();

      DataType dataType = null;

      for (FieldValue value : values) {

        // "Missing values in the input to an aggregate function are simply ignored"
        if (value == null) {
          continue;
        }

        statistic.increment((value.asNumber()).doubleValue());

        if (dataType != null) {
          dataType = TypeUtil.getResultDataType(dataType, value.getDataType());
        } else {
          dataType = value.getDataType();
        }
      }

      if (statistic.getN() == 0) {
        throw new MissingResultException(null);
      }

      Object result = cast(getResultType(dataType), statistic.getResult());

      return FieldValueUtil.create(result);
    }
Esempio n. 4
0
 /**
  * Remove a field/value pairing. This is sometimes needed in cases where an LSPDoc is created from
  * some underlying collection before the "answer-fields" criterion can be applied. When that
  * happens, the criterion is applied during post-processing, and sometimes field/value pairings
  * have to be removed.
  *
  * @param field the field in the field/value pairing to be removed
  */
 public void removeFieldValue(LSPField field) {
   for (Iterator it = fieldValues.iterator(); it.hasNext(); ) {
     FieldValue fv = (FieldValue) it.next();
     if (fv.getField().equals(field)) {
       it.remove();
       break;
     }
   }
 }
Esempio n. 5
0
    @Override
    public FieldValue evaluate(List<FieldValue> values) {
      checkArguments(values, 1);

      FieldValue value = values.get(0);

      String result = evaluate(value.asString());

      return FieldValueUtil.create(result);
    }
Esempio n. 6
0
    @Override
    public FieldValue evaluate(List<FieldValue> values) {
      checkArguments(values, 1);

      FieldValue value = values.get(0);

      Number result = cast(getResultType(value.getDataType()), evaluate(value.asNumber()));

      return FieldValueUtil.create(result);
    }
Esempio n. 7
0
 /**
  * Gets the value from a particular field name
  *
  * @param fieldName (use one from {@link edu.columbia.cs.sdarts.common.FieldNames FieldNames})
  * @return value the value for that field
  */
 public String getValue(String fieldName) {
   if (fieldValues == null) {
     return null;
   }
   int len = fieldValues.size();
   for (int i = 0; i < len; i++) {
     FieldValue fv = (FieldValue) fieldValues.get(i);
     if (fv.getField().getName().equals(fieldName)) {
       return fv.getValue().getValue();
     }
   }
   return null;
 }
Esempio n. 8
0
  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("(");

    if (!isEmpty()) {
      Iterator<FieldValue> i = iterator();
      FieldValue fv = i.next();
      sb.append(fv.toString());

      while (i.hasNext()) {
        sb.append(", ");
        fv = i.next();
        sb.append(fv.toString());
      }
    }

    sb.append(")");
    return sb.toString();
  }
Esempio n. 9
0
    @Override
    public FieldValue evaluate(List<FieldValue> values) {

      if (values.size() != 2) {
        throw new EvaluationException();
      }

      FieldValue left = values.get(0);
      FieldValue right = values.get(1);

      // "If one of the input fields of a simple arithmetic function is a missing value, the result
      // evaluates to missing value"
      if (left == null || right == null) {
        return null;
      }

      DataType dataType = TypeUtil.getResultDataType(left.getDataType(), right.getDataType());

      Number result;

      try {
        result = evaluate(left.asNumber(), right.asNumber());
      } catch (ArithmeticException ae) {
        throw new InvalidResultException(null);
      }

      return FieldValueUtil.create(cast(dataType, result));
    }
  private double[] createInput(EvaluationContext context) {
    SupportVectorMachineModel supportVectorMachineModel = getModel();

    VectorDictionary vectorDictionary = supportVectorMachineModel.getVectorDictionary();

    VectorFields vectorFields = vectorDictionary.getVectorFields();

    List<FieldRef> fieldRefs = vectorFields.getFieldRefs();

    double[] result = new double[fieldRefs.size()];

    for (int i = 0; i < fieldRefs.size(); i++) {
      FieldRef fieldRef = fieldRefs.get(i);

      FieldValue value = ExpressionUtil.evaluate(fieldRef, context);
      if (value == null) {
        throw new MissingValueException(fieldRef.getField(), vectorFields);
      }

      result[i] = (value.asNumber()).doubleValue();
    }

    return result;
  }
Esempio n. 11
0
 /**
  * Returns field value corresponding to input number
  *
  * @param num the number corresponding to field value
  * @return corresponding field value, otherwise null
  */
 public static FieldValue fromInt(int num) {
   for (int i = 0; i < 10; i++)
     if (FieldValue.values()[i].getNumber() == num) return FieldValue.values()[i];
   return null;
 }
 public void visit(FieldValue operand) {
   operand.parent().accept(this);
 }
  public void doCreate(IOTransaction ioTransaction) throws FilterException {
    ArticleTransaction transaction = null;
    if (ioTransaction instanceof ArticleTransaction) {
      transaction = (ArticleTransaction) ioTransaction;
    } else {
      return;
    }
    if (!"escenic-migration".equals(transaction.getSource())) {
      logger.debug("not a migration article. ignoring...");
      return;
    }
    for (String relationType : relationTypes) {
      List<ContentSummary> summaryList = transaction.getContentSummaries(relationType);
      List<ContentSummary> newSummaryList = new ArrayList<ContentSummary>();

      for (ContentSummary summary : summaryList) {
        int relatedId = IOHashKey.valueOf(summary.getContentLink().getHref()).getObjectId();
        logger.debug("loading article id : " + relatedId);
        Article relatedArticle = loader.getArticle(relatedId);

        List<PropertyDescriptor> propertyDescriptors =
            summary.getDescriptor().getPropertyDescriptors();

        for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
          if (summary.getProperty(propertyDescriptor) != null
              && !"".equals(summary.getProperty(propertyDescriptor).toString().trim())) {
            logger.debug("Summary field already has a value. Skiping...");
            continue;
          }
          String fieldName = propertyDescriptor.getName();
          FieldValue field = null;
          try {
            field = relatedArticle.getField(fieldName);
          } catch (IllegalArgumentException ex) {
            logger.debug("field '" + fieldName + "' does not exist");
          }
          if (field != null) {
            Object fieldValue = field.getValue();
            logger.debug("setting summary field " + fieldName + " value = " + fieldValue);
            summary.setProperty(propertyDescriptor, fieldValue);
          }
        }
        newSummaryList.add(summary);
      }
      logger.debug("setting new content summaries");
      transaction.setContentSummaries(relationType, newSummaryList);
    }
    //        for (String relationType : relationTypes)  {
    //            List<ContentSummary> summaryList = transaction.getContentSummaries(relationType);
    //            List<ContentSummary> newSummaryList = new ArrayList<ContentSummary>();
    //            logger.debug("removed all from content summaries for relation " + relationType);
    //            for (int i = 0; i < summaryList.size(); i++) {
    //                int relatedId =
    // IOHashKey.valueOf(summaryList.get(i).getContentLink().getHref()).getObjectId();
    //                logger.debug("loading article id : " + relatedId);
    //                Article relatedArticle = loader.getArticle(relatedId);
    //                ContentSummary newContentSummary = relatedArticle.toContentSummary();
    //                logger.debug("newContentSummary = " + newContentSummary);
    //                newSummaryList.add( newContentSummary);
    //            }
    //            logger.debug("setting new content summaries for relation " + relationType);
    //            transaction.setContentSummaries(relationType, newSummaryList);
    //            transaction.setContentSummaries(relationType.toLowerCase(), newSummaryList);
    //
    //        }
  }