Пример #1
0
  public void startScanFeatures(Observation obsr) {
    currentFeatures.clear();
    currentFeatureIdx = 0;

    // scan over all context predicates
    for (int i = 0; i < obsr.cps.length; i++) {
      Element elem = (Element) dict.dict.get(new Integer(obsr.cps[i]));
      if (elem == null) {
        continue;
      }

      if (!(elem.isScanned)) {
        // scan all labels for features
        Iterator it = elem.lbCntFidxes.keySet().iterator();
        while (it.hasNext()) {
          Integer labelInt = (Integer) it.next();
          CountFIdx cntFIdx = (CountFIdx) elem.lbCntFidxes.get(labelInt);

          if (cntFIdx.fidx >= 0) {
            Feature f = new Feature();
            f.FeatureInit(labelInt.intValue(), obsr.cps[i]);
            f.idx = cntFIdx.fidx;

            elem.cpFeatures.add(f);
          }
        }

        elem.isScanned = true;
      }

      for (int j = 0; j < elem.cpFeatures.size(); j++) {
        currentFeatures.add(elem.cpFeatures.get(j));
      }
    }
  }
Пример #2
0
    public static void printNeighbors(ArrayList neighbors) {
        int i = 0;
        for(Neighbor neighbor : neighbors) {
            Instance instance = neighbor.getInstance();

            System.out.println("\nNeighbor " + (i + 1) + ", distance: " + neighbor.getDistance());
            i++;
            for(Feature f : instance.getAttributes()) {
                System.out.print(f.getName() + ": ");
                if(f instanceof Category) {
                    System.out.println(((Category)f).getCategory().toString());
                }
                else if(f instanceof Distance) {
                    System.out.println(((Distance)f).getDistance().toString());
                }
                else if (f instanceof Expiration) {
                    System.out.println(((Expiration)f).getExpiry().toString());
                }
                else if (f instanceof Handset) {
                    System.out.print(((Handset)f).getOs().toString() + ", ");
                    System.out.println(((Handset)f).getDevice().toString());
                }
                else if (f instanceof Offer) {
                    System.out.println(((Offer)f).getOfferType().toString());
                }
                else if (f instanceof WSAction) {
                    System.out.println(((WSAction)f).getAction().toString());
                }
            }
        }
    }
 /*
  * Create and return a new feature object with the given parameters.
  */
 public Feature createFeature(Site site, String id, String version, String url) {
   Feature result = new Feature(site);
   result.setId(id);
   result.setVersion(version);
   result.setUrl(url);
   return result;
 }
Пример #4
0
 public static void add(Object tag, Geometry geom, String msg) {
   if (!Debug.isDebugging()) return;
   FeatureDataset fd = getDebugFeatureDataset(tag);
   Feature feature = new BasicFeature(fd.getFeatureSchema());
   feature.setGeometry(geom);
   feature.setAttribute(MESG_ATTR_NAME, msg);
   fd.add(feature);
 }
Пример #5
0
 public static Feature createLineSegmentFeature(
     FeatureSchema fs, Coordinate p0, Coordinate p1, String msg) {
   Feature feature = new BasicFeature(fs);
   LineString lineSeg = fact.createLineString(new Coordinate[] {p0, p1});
   feature.setGeometry(lineSeg);
   feature.setAttribute(MESG_ATTR_NAME, msg);
   return feature;
 }
 private String getTypeOfResponseVariable(String responseVariable, List<Feature> features) {
   String type = null;
   for (Feature feature : features) {
     if (feature.getName().equals(responseVariable)) {
       type = feature.getType();
     }
   }
   return type;
 }
Пример #7
0
  public void writeFeatures(PrintWriter fout) throws IOException {
    // write the number of features
    fout.println(Integer.toString(features.size()));

    for (int i = 0; i < features.size(); i++) {
      Feature f = (Feature) features.get(i);
      fout.println(f.toString(data.cpInt2Str, data.lbInt2Str));
    }

    // wirte the line ###...
    fout.println(Option.modelSeparator);
  }
Пример #8
0
  /**
   * look at all the data in the column of the featurecollection, and find the largest string!
   *
   * @param fc features to look at
   * @param attributeNumber which of the column to test.
   */
  int findMaxStringLength(FeatureCollection fc, int attributeNumber) {
    int l;
    int maxlen = 0;
    Feature f;

    for (Iterator i = fc.iterator(); i.hasNext(); ) {
      f = (Feature) i.next();
      l = f.getString(attributeNumber).length();

      if (l > maxlen) {
        maxlen = l;
      }
    }

    return maxlen;
  }
  public double classify(List<String> words) {

    double score = 0.0;
    double right = 1.0;
    int count = 0;

    List<Feature> features = kindTagging(words);

    for (Feature feature : features) {
      //            logger.info("details: {}", feature.getText() + ": " + feature.getScore() + "; "
      // + feature.getMultiple() + "; " + feature.getKind());
      if (feature.getMultiple() != 0) {
        right *= feature.getMultiple();
      }
      if (feature.getScore() != 0) {
        score += right * feature.getScore();
        count++;
        right = 1.0;
      }
      if (feature.getMultiple() == 0) {
        right = 1.0;
      }
    }

    if (count != 0) {
      score = score / count;
    }
    // System.out.println("sss " +score);
    return score;
  }
Пример #10
0
 public static void printClassificationInstance(Instance classificationInstance) {
     for(Feature f : classificationInstance.getAttributes()) {
         System.out.print(f.getName() + ": ");
         if(f instanceof Category) {
             System.out.println(((Category)f).getCategory().toString());
         }
         else if(f instanceof Distance) {
             System.out.println(((Distance)f).getDistance().toString());
         }
         else if (f instanceof Expiration) {
             System.out.println(((Expiration)f).getExpiry().toString());
         }
         else if (f instanceof Handset) {
             System.out.print(((Handset)f).getOs().toString() + ", ");
             System.out.println(((Handset)f).getDevice().toString());
         }
         else if (f instanceof Offer) {
             System.out.println(((Offer)f).getOfferType().toString());
         }
         else if (f instanceof WSAction) {
             System.out.println(((WSAction)f).getAction().toString());
         }
     }
 }
Пример #11
0
  /**
   * Add a feature to this map. Note that the start of the feature should be a smaller number than
   * the stop of the feature, regardless of the strand. The only case where start is larger than the
   * stop is when the feature runs across the start/stop boundary, for example 6899-10 on a 7000bp
   * plasmid.
   *
   * @param type one of the following: origin_of_replication, promoter, terminator,
   *     selectable_marker, regulatory_sequence, tag, other_gene, reporter_gene,
   *     unique_restriction_site, restriction_site.
   * @param name the name of the feature, such as EcoRI.
   * @param start the start position of the feature. Must be between 1 and the length of the
   *     plasmid.
   * @param stop the end position of the feature. Must be between 1 and the length of the plasmid.
   * @param strand the strand of the feature. Can be Plasmid.FORWARD, Plasmid.REVERSE, or
   *     Plasmid.NO_DIRECTION.
   */
  public void addFeature(String type, String name, int start, int stop, int strand) {
    // add the feature to the plasmid.
    int decoration;
    int label;
    Color color;
    // String slot;

    if (start > size) {
      start = size;
    }
    if (start < 1) {
      start = 1;
    }

    if (stop > size) {
      stop = size;
    }
    if (stop < 1) {
      stop = 1;
    }

    try {
      color = getFeatureColor(type);
      decoration = getFeatureDecoration(type, strand);
      label = getLabelType();
      addItemToLegend(type, strand);
    } catch (NullPointerException e) {
      color = new Color(0, 0, 128); // navy
      if (colorScheme == REGULAR) {
        color = new Color(0, 0, 128); // navy
      } else if (colorScheme == INVERSE) {
        color = new Color(0, 128, 128); // teal
      }
      decoration = DECORATION_STANDARD;
      label = LABEL;
    }

    // create a feature and a feature range
    // then figure out which feature slot to put the feature in.
    Feature feature = new Feature(showShading);
    FeatureRange featureRange = new FeatureRange(feature, start, stop);
    featureRange.setDecoration(decoration);
    featureRange.setColor(color);
    featureRange.setOpacity(opacity);
    featureRange.setShowLabel(label);
    if ((showPositions)
        && ((type.equalsIgnoreCase("restriction_site"))
            || (type.equalsIgnoreCase("unique_restriction_site")))) {
      featureRange.setLabel(name + " " + start);
    } else {
      if (addCategoryInfo) {
        try {
          featureRange.setLabel(name + (String) FEATURE_CATEGORIES.get(type));
        } catch (NullPointerException e) {
          featureRange.setLabel(name);
        }
      } else {
        featureRange.setLabel(name);
      }
    }

    if ((type.equalsIgnoreCase("restriction_site"))
        || (type.equalsIgnoreCase("unique_restriction_site"))) {
      if (restrictionSlot == null) {
        restrictionSlot = new FeatureSlot(DIRECT_STRAND, showShading);
        restrictionSlot.setFeatureThickness(1f);
      }
      feature.setFeatureSlot(restrictionSlot);
    } else if ((strand == NO_DIRECTION) || (strand == FORWARD)) {
      if (forwardSlot0 == null) {
        forwardSlot0 = new FeatureSlot(DIRECT_STRAND, showShading);
        feature.setFeatureSlot(forwardSlot0);
      } else if (forwardSlot0.isRoom(feature)) {
        feature.setFeatureSlot(forwardSlot0);
      } else if (forwardSlot1 == null) {
        forwardSlot1 = new FeatureSlot(DIRECT_STRAND, showShading);
        feature.setFeatureSlot(forwardSlot1);
      } else if (forwardSlot1.isRoom(feature)) {
        feature.setFeatureSlot(forwardSlot1);
      } else if (forwardSlot2 == null) {
        forwardSlot2 = new FeatureSlot(DIRECT_STRAND, showShading);
        feature.setFeatureSlot(forwardSlot2);
      } else if (forwardSlot2.isRoom(feature)) {
        feature.setFeatureSlot(forwardSlot2);
      } else if (forwardSlot3 == null) {
        forwardSlot3 = new FeatureSlot(DIRECT_STRAND, showShading);
        feature.setFeatureSlot(forwardSlot3);
      } else if (forwardSlot3.isRoom(feature)) {
        feature.setFeatureSlot(forwardSlot3);
      } else if (forwardSlot4 == null) {
        forwardSlot4 = new FeatureSlot(DIRECT_STRAND, showShading);
        feature.setFeatureSlot(forwardSlot4);
      } else if (forwardSlot4.isRoom(feature)) {
        feature.setFeatureSlot(forwardSlot4);
      } else if (forwardSlot5 == null) {
        forwardSlot5 = new FeatureSlot(DIRECT_STRAND, showShading);
        feature.setFeatureSlot(forwardSlot5);
      } else if (forwardSlot5.isRoom(feature)) {
        feature.setFeatureSlot(forwardSlot5);
      } else if (forwardSlot6 == null) {
        forwardSlot6 = new FeatureSlot(DIRECT_STRAND, showShading);
        feature.setFeatureSlot(forwardSlot6);
      } else if (forwardSlot6.isRoom(feature)) {
        feature.setFeatureSlot(forwardSlot6);
      } else if (forwardSlot7 == null) {
        forwardSlot7 = new FeatureSlot(DIRECT_STRAND, showShading);
        feature.setFeatureSlot(forwardSlot7);
      } else {
        feature.setFeatureSlot(forwardSlot7);
      }

    } else if (strand == REVERSE) {
      if (reverseSlot0 == null) {
        reverseSlot0 = new FeatureSlot(REVERSE_STRAND, showShading);
        feature.setFeatureSlot(reverseSlot0);
      } else if (reverseSlot0.isRoom(feature)) {
        feature.setFeatureSlot(reverseSlot0);
      } else if (reverseSlot1 == null) {
        reverseSlot1 = new FeatureSlot(REVERSE_STRAND, showShading);
        feature.setFeatureSlot(reverseSlot1);
      } else if (reverseSlot1.isRoom(feature)) {
        feature.setFeatureSlot(reverseSlot1);
      } else if (reverseSlot2 == null) {
        reverseSlot2 = new FeatureSlot(REVERSE_STRAND, showShading);
        feature.setFeatureSlot(reverseSlot2);
      } else if (reverseSlot2.isRoom(feature)) {
        feature.setFeatureSlot(reverseSlot2);
      } else if (reverseSlot3 == null) {
        reverseSlot3 = new FeatureSlot(REVERSE_STRAND, showShading);
        feature.setFeatureSlot(reverseSlot3);
      } else if (reverseSlot3.isRoom(feature)) {
        feature.setFeatureSlot(reverseSlot3);
      } else if (reverseSlot4 == null) {
        reverseSlot4 = new FeatureSlot(REVERSE_STRAND, showShading);
        feature.setFeatureSlot(reverseSlot4);
      } else if (reverseSlot4.isRoom(feature)) {
        feature.setFeatureSlot(reverseSlot4);
      } else if (reverseSlot5 == null) {
        reverseSlot5 = new FeatureSlot(REVERSE_STRAND, showShading);
        feature.setFeatureSlot(reverseSlot5);
      } else if (reverseSlot5.isRoom(feature)) {
        feature.setFeatureSlot(reverseSlot5);
      } else if (reverseSlot6 == null) {
        reverseSlot6 = new FeatureSlot(REVERSE_STRAND, showShading);
        feature.setFeatureSlot(reverseSlot6);
      } else if (reverseSlot6.isRoom(feature)) {
        feature.setFeatureSlot(reverseSlot6);
      } else if (reverseSlot7 == null) {
        reverseSlot7 = new FeatureSlot(REVERSE_STRAND, showShading);
        feature.setFeatureSlot(reverseSlot7);
      } else {
        feature.setFeatureSlot(reverseSlot7);
      }
    }
  }
 public List<Feature> kindTagging(List<String> words) {
   List<Feature> features = new ArrayList<Feature>();
   for (String word : words) {
     Feature feature = new Feature();
     feature.setText(word);
     if (isPrivativeWord(word)) {
       // System.out.println("bubnububub");
       feature.setKind(Enum.valueOf(WordType.class, "PRIVATIVE"));
       feature.setMultiple(-1.0);
     } else if (isDecoVeryWord(word)) {
       feature.setKind(Enum.valueOf(WordType.class, "DECORATEVERY"));
       feature.setMultiple(2.0);
     } else if (isDecoLittleWord(word)) {
       feature.setKind(Enum.valueOf(WordType.class, "DECORATELITTLE"));
       feature.setMultiple(0.5);
     } else if (isPositiveWord(word)) {
       feature.setKind(Enum.valueOf(WordType.class, "POSITIVE"));
       feature.setMultiple(1.0);
       feature.setScore(posiLexicon.get(word));
     } else if (isNegativeWord(word)) {
       feature.setKind(Enum.valueOf(WordType.class, "NEGATIVE"));
       feature.setMultiple(-1.0);
       feature.setScore(negaLexicon.get(word));
     }
     features.add(feature);
   }
   return features;
 }
Пример #13
0
  // generating features
  public void generateFeatures() {
    if (features != null) {
      features.clear();
    } else {
      features = new ArrayList();
    }

    if (fmap != null) {
      fmap.clear();
    } else {
      fmap = new HashMap();
    }

    if (currentFeatures != null) {
      currentFeatures.clear();
    } else {
      currentFeatures = new ArrayList();
    }

    if (data.trnData == null || dict.dict == null) {
      System.out.println("No data or dictionary for generating features");
      return;
    }

    // scan over data list
    for (int i = 0; i < data.trnData.size(); i++) {
      Observation obsr = (Observation) data.trnData.get(i);

      for (int j = 0; j < obsr.cps.length; j++) {
        Element elem;
        CountFIdx cntFIdx;

        elem = (Element) dict.dict.get(new Integer(obsr.cps[j]));
        if (elem != null) {
          if (elem.count <= option.cpRareThreshold) {
            // skip this context predicate, it is too rare
            continue;
          }

          cntFIdx = (CountFIdx) elem.lbCntFidxes.get(new Integer(obsr.humanLabel));
          if (cntFIdx != null) {
            if (cntFIdx.count <= option.fRareThreshold) {
              // skip this feature, it is too rare
              continue;
            }

          } else {
            // not found in the dictionary, then skip
            continue;
          }

        } else {
          // not found in the dictionary, then skip
          continue;
        }

        // update the feature
        Feature f = new Feature(obsr.humanLabel, obsr.cps[j]);
        f.strId2Idx(fmap);
        if (f.idx < 0) {
          // new feature, add to the feature list
          addFeature(f);

          // update the feature index in the dictionary
          cntFIdx.fidx = f.idx;
          elem.chosen = 1;
        }
      }
    }

    option.numFeatures = features.size();
  }
Пример #14
0
 // adding a feature
 public void addFeature(Feature f) {
   f.strId2IdxAdd(fmap);
   features.add(f);
 }
Пример #15
0
  /**
   * Write a dbf file with the information from the featureCollection.
   *
   * @param featureCollection column data from collection
   * @param fname name of the dbf file to write to
   */
  void writeDbf(FeatureCollection featureCollection, String fname) throws Exception {
    DbfFileWriter dbf;
    FeatureSchema fs;
    int t;
    int f;
    int u;
    int num;

    fs = featureCollection.getFeatureSchema();

    // -1 because one of the columns is geometry
    DbfFieldDef[] fields = new DbfFieldDef[fs.getAttributeCount() - 1];

    // dbf column type and size
    f = 0;

    for (t = 0; t < fs.getAttributeCount(); t++) {
      AttributeType columnType = fs.getAttributeType(t);
      String columnName = fs.getAttributeName(t);

      if (columnType == AttributeType.INTEGER) {
        fields[f] = new DbfFieldDef(columnName, 'N', 16, 0);
        f++;
      } else if (columnType == AttributeType.DOUBLE) {
        fields[f] = new DbfFieldDef(columnName, 'N', 33, 16);
        f++;
      } else if (columnType == AttributeType.STRING) {
        int maxlength = findMaxStringLength(featureCollection, t);

        if (maxlength > 255) {
          throw new Exception(
              "ShapefileWriter does not support strings longer than 255 characters");
        }

        fields[f] = new DbfFieldDef(columnName, 'C', maxlength, 0);
        f++;
      } else if (columnType == AttributeType.DATE) {
        fields[f] = new DbfFieldDef(columnName, 'D', 8, 0);
        f++;
      } else if (columnType == AttributeType.GEOMETRY) {
        // do nothing - the .shp file handles this
      } else {
        throw new Exception("Shapewriter: unsupported AttributeType found in featurecollection.");
      }
    }

    // write header
    dbf = new DbfFileWriter(fname);
    dbf.writeHeader(fields, featureCollection.size());

    // write rows
    num = featureCollection.size();

    List features = featureCollection.getFeatures();

    for (t = 0; t < num; t++) {
      // System.out.println("dbf: record "+t);
      Feature feature = (Feature) features.get(t);
      Vector DBFrow = new Vector();

      // make data for each column in this feature (row)
      for (u = 0; u < fs.getAttributeCount(); u++) {
        AttributeType columnType = fs.getAttributeType(u);

        if (columnType == AttributeType.INTEGER) {
          Object a = feature.getAttribute(u);

          if (a == null) {
            DBFrow.add(new Integer(0));
          } else {
            DBFrow.add((Integer) a);
          }
        } else if (columnType == AttributeType.DOUBLE) {
          Object a = feature.getAttribute(u);

          if (a == null) {
            DBFrow.add(new Double(0.0));
          } else {
            DBFrow.add((Double) a);
          }
        } else if (columnType == AttributeType.DATE) {
          Object a = feature.getAttribute(u);
          if (a == null) {
            DBFrow.add("");
          } else {
            DBFrow.add(DbfFile.DATE_PARSER.format((Date) a));
          }
        } else if (columnType == AttributeType.STRING) {
          Object a = feature.getAttribute(u);

          if (a == null) {
            DBFrow.add(new String(""));
          } else {
            // MD 16 jan 03 - added some defensive programming
            if (a instanceof String) {
              DBFrow.add(a);
            } else {
              DBFrow.add(a.toString());
            }
          }
        }
      }

      dbf.writeRecord(DBFrow);
    }

    dbf.close();
  }
Пример #16
0
 public void addDefinition(Feature definition) {
   definitions.put(definition.getID(), definition);
 }
Пример #17
0
 public String getDescriptionForID(String id) {
   Feature x = (Feature) definitions.get(id);
   if (x != null) return x.getDescription();
   else return "?";
 }
Пример #18
0
 public Feature buildFeature(String id) {
   Feature x = (Feature) definitions.get(id);
   if (x != null) return (Feature) x.clone();
   Debug.byebye("Feature " + id + " not found");
   return null;
 }