Package org.maltparserx.core.feature

Examples of org.maltparserx.core.feature.FeatureException


  public void add(int index, String subModelName, String featureSpec) throws MaltChainedException {
    this.add(Integer.toString(index), subModelName, featureSpec);
  }
 
  public void add(String specModelName, String subModelName, String featureSpec) throws MaltChainedException {
    if (featureSpec == null) { throw new FeatureException("Feature specification is missing."); }
    if (specModelName == null) {throw new FeatureException("Unknown feature model name."); }
    if (subModelName == null) {throw new FeatureException("Unknown subfeature model name."); }
   
    if (!specModelMap.containsKey(specModelName.toUpperCase())) {
      SpecificationModel specModel = new SpecificationModel(specModelName.toUpperCase());
      specModelMap.put(specModelName.toUpperCase(), specModel);
      currentSpecModelURL.add(specModel);
View Full Code Here


    return counter;
  }
 
  public void loadParReader(URL specModelURL, String markingStrategy, String coveredRoot) throws MaltChainedException {
    if (specModelURL == null) {
      throw new FeatureException("The URL to the feature specification model is missing or not well-formed. ");
    }
    FeatureSpecReader specReader = null;
    String urlSuffix = specModelURL.toString().substring(specModelURL.toString().length()-3);
    urlSuffix = Character.toUpperCase(urlSuffix.charAt(0)) + urlSuffix.substring(1);
    try {
      Class<?> clazz = Class.forName("org.maltparserx.core.feature.spec.reader."+urlSuffix+"Reader");
      specReader = (FeatureSpecReader)clazz.newInstance();
    } catch (InstantiationException e) {
      throw new FeatureException("Could not initialize the feature specification reader to read the specification file: "+specModelURL.toString(), e);
    } catch (IllegalAccessException e) {
      throw new FeatureException("Could not initialize the feature specification reader to read the specification file: "+specModelURL.toString(), e);
    } catch (ClassNotFoundException e) {
      throw new FeatureException("Could not find the feature specification reader to read the specification file: "+specModelURL.toString(), e);
    }
    specReaderMap.put(specModelURL, specReader);
   
    if (specReader instanceof ParReader) {
      if (markingStrategy.equalsIgnoreCase("head") || markingStrategy.equalsIgnoreCase("path") || markingStrategy.equalsIgnoreCase("head+path")) {
View Full Code Here

    specReader.load(specModelURL, this);
  }
 
  public void load(URL specModelURL) throws MaltChainedException {
    if (specModelURL == null) {
      throw new FeatureException("The URL to the feature specification model is missing or not well-formed. ");
    }
    FeatureSpecReader specReader = null;
    String urlSuffix = specModelURL.toString().substring(specModelURL.toString().length()-3);
    urlSuffix = Character.toUpperCase(urlSuffix.charAt(0)) + urlSuffix.substring(1);
    try {
      Class<?> clazz = Class.forName("org.maltparserx.core.feature.spec.reader."+urlSuffix+"Reader");
      specReader = (FeatureSpecReader)clazz.newInstance();
    } catch (InstantiationException e) {
      throw new FeatureException("Could not initialize the feature specification reader to read the specification file: "+specModelURL.toString(), e);
    } catch (IllegalAccessException e) {
      throw new FeatureException("Could not initialize the feature specification reader to read the specification file: "+specModelURL.toString(), e);
    } catch (ClassNotFoundException e) {
      throw new FeatureException("Could not find the feature specification reader to read the specification file: "+specModelURL.toString(), e);
    }
    specReaderMap.put(specModelURL, specReader);
   
    currentSpecModelURL = new ArrayList<SpecificationModel>();
    specModelKeyMap.put(specModelURL, currentSpecModelURL);
View Full Code Here

 
  public void load(URL specModelURL, SpecificationModels featureSpecModels) throws MaltChainedException {
    BufferedReader br = null;
    Pattern tabPattern = Pattern.compile("\t");
    if (specModelURL == null) {
      throw new FeatureException("The feature specification file cannot be found. ");
    }
    try {
      br = new BufferedReader(new InputStreamReader(specModelURL.openStream()));
    } catch (IOException e) {
      throw new FeatureException("Could not read the feature specification file '"+specModelURL.toString()+"'. ", e);
    }   
   
    if (br != null) {
      int specModelIndex = featureSpecModels.getNextIndex();
      String fileLine;
      String items[];
      StringBuilder featureText = new StringBuilder();
      String splitfeats = "";
      ArrayList<String> fileLines = new ArrayList<String>();
      ArrayList<String> orderFileLines = new ArrayList<String>();
      while (true) {
        try {
          fileLine = br.readLine();
        } catch (IOException e) {
          throw new FeatureException("Could not read the feature specification file '"+specModelURL.toString()+"'. ", e);
        }
        if (fileLine == null) {
          break;
        }
        if (fileLine.length() <= 1 && fileLine.trim().substring(0, 2).trim().equals("--")) {
          continue;
        }
        fileLines.add(fileLine);
      }
      try {
        br.close();
      } catch (IOException e) {
        throw new FeatureException("Could not close the feature specification file '"+specModelURL.toString()+"'. ", e);
      }

      for (int j = 0; j < fileLines.size(); j++) {
        orderFileLines.add(fileLines.get(j));
      }

      boolean deprel = false;
      for (int j=0; j < orderFileLines.size(); j++) {
        deprel = false;
        featureText.setLength(0);
        splitfeats = "";
        items = tabPattern.split(orderFileLines.get(j));
        if (items.length < 2) {
          throw new FeatureException("The feature specification file '"+specModelURL.toString()+"' must contain at least two columns.");
        }
        if (!(columnNameMap.containsKey(ColumnNames.valueOf(items[0].trim())) || columnNameMap.containsValue(items[0].trim()))) {
          throw new FeatureException("Column one in the feature specification file '"+specModelURL.toString()+"' contains an unknown value '"+items[0].trim()+"'. ");
        }
        if (items[0].trim().equalsIgnoreCase("DEP") || items[0].trim().equalsIgnoreCase("DEPREL")) {
          featureText.append("OutputColumn(DEPREL, ");
          deprel = true;
        } else {
          if (columnNameMap.containsKey(ColumnNames.valueOf(items[0].trim()))) {
            featureText.append("InputColumn("+columnNameMap.get(ColumnNames.valueOf(items[0].trim()))+", ");
          } else if (columnNameMap.containsValue(items[0].trim())) {
            featureText.append("InputColumn("+items[0].trim()+", ");
          }
          if (items[0].trim().equalsIgnoreCase("FEATS") && isUseSplitFeats()) {
            splitfeats = "Split(";
          }
        }
        if (!(items[1].trim().equalsIgnoreCase("STACK") || items[1].trim().equalsIgnoreCase("INPUT") || items[1].trim().equalsIgnoreCase("CONTEXT"))) {
          throw new FeatureException("Column two in the feature specification file '"+specModelURL.toString()+"' should be either 'STACK', 'INPUT' or 'CONTEXT' (Covington), not '"+items[1].trim()+"'. ");
        }
        int offset = 0;
        if (items.length >= 3) {
          try {
            offset = new Integer(Integer.parseInt(items[2]));
          } catch (NumberFormatException e) {
            throw new FeatureException("The feature specification file '"+specModelURL.toString()+"' contains a illegal integer value. ", e);
          }
        }
        String functionArg = "";
       
        if (items[1].trim().equalsIgnoreCase("CONTEXT")) {
          if (offset >= 0) {
            functionArg = dataStructuresMap.get(DataStructures.valueOf("LEFTCONTEXT"))+"["+offset+"]";
          } else {
            functionArg = dataStructuresMap.get(DataStructures.valueOf("RIGHTCONTEXT"))+"["+Math.abs(offset + 1)+"]";
          }
        } else if (dataStructuresMap.containsKey(DataStructures.valueOf(items[1].trim()))) {
          if (covington == true) {
            if (dataStructuresMap.get(DataStructures.valueOf(items[1].trim())).equalsIgnoreCase("Stack")) {
              functionArg = "Left["+offset+"]";
            } else {
              functionArg = "Right["+offset+"]";
            }
          } else {
            functionArg = dataStructuresMap.get(DataStructures.valueOf(items[1].trim()))+"["+offset+"]";
          }
        } else if (dataStructuresMap.containsValue(items[1].trim())) {
          if (covington == true) {
            if (items[1].trim().equalsIgnoreCase("Stack")) {
              functionArg = "Left["+offset+"]";
            } else {
              functionArg = "Right["+offset+"]";
            }
          } else {
            functionArg = items[1].trim()+"["+offset+"]";
          }
         
        } else {
          throw new FeatureException("Column two in the feature specification file '"+specModelURL.toString()+"' should not contain the value '"+items[1].trim());
        }
 
        int linearOffset = 0;
        int headOffset = 0;
        int depOffset = 0;
        int sibOffset = 0;
        int suffixLength = 0;
        if (items.length >= 4) { linearOffset = new Integer(Integer.parseInt(items[3])); }
        if (items.length >= 5) { headOffset = new Integer(Integer.parseInt(items[4])); }
        if (items.length >= 6) { depOffset = new Integer(Integer.parseInt(items[5])); }
        if (items.length >= 7) { sibOffset = new Integer(Integer.parseInt(items[6])); }
        if (items.length >= 8) { suffixLength = new Integer(Integer.parseInt(items[7])); }
        if (linearOffset < 0) {
          linearOffset = Math.abs(linearOffset);
          for (int i = 0; i < linearOffset; i++) {
            functionArg = "pred("+functionArg+")";
          }
        } else if (linearOffset > 0) {
          for (int i = 0; i < linearOffset; i++) {
            functionArg = "succ("+functionArg+")";
          }
        }
        if (headOffset >= 0) {
          for (int i = 0; i < headOffset; i++) {
            functionArg = "head("+functionArg+")";
          }
        } else {
          throw new FeatureException("The feature specification file '"+specModelURL.toString()+"' should not contain a negative head function value. ");
        }
        if (depOffset < 0) {
          depOffset = Math.abs(depOffset);
          for (int i = 0; i < depOffset; i++) {
            functionArg = "ldep("+functionArg+")";
View Full Code Here

            Element root = null;

            root = db.parse(specModelURL.openStream()).getDocumentElement();

            if (root == null) {
              throw new FeatureException("The feature specification file '"+specModelURL.getFile()+"' cannot be found. ");
            }
           
            readFeatureModels(root, featureSpecModels);
        } catch (IOException e) {
          throw new FeatureException("The feature specification file '"+specModelURL.getFile()+"' cannot be found. ", e);
        } catch (SAXParseException e) {
          throw new FeatureException("Problem parsing the feature specification XML-file "+specModelURL.getFile()+". ", e);
        } catch (ParserConfigurationException e) {
          throw new FeatureException("Problem parsing the feature specification XML-file "+specModelURL.getFile()+". ", e);
        } catch (SAXException e) {
          throw new FeatureException("Problem parsing the feature specification XML-file "+specModelURL.getFile()+". ", e);
        }
  }
View Full Code Here

    multipleFeatureValue = new MultipleFeatureValue(this);
  }
 
  public void initialize(Object[] arguments) throws MaltChainedException {
    if (arguments.length != 2) {
      throw new FeatureException("Could not initialize SplitFeature: number of arguments are not correct. ");
    }
    if (!(arguments[0] instanceof FeatureFunction)) {
      throw new FeatureException("Could not initialize SplitFeature: the first argument is not a feature. ");
    }
    if (!(arguments[1] instanceof String)) {
      throw new FeatureException("Could not initialize SplitFeature: the second argument is not a string. ");
    }
    setParentFeature((FeatureFunction)arguments[0]);
    setSeparators((String)arguments[1]);
    ColumnDescription parentColumn = dataFormatInstance.getColumnDescriptionByName(parentFeature.getSymbolTable().getName());
    if (parentColumn.getType() != ColumnDescription.STRING) {
      throw new FeatureException("Could not initialize SplitFeature: the first argument must be a string. ");
    }
    setColumn(dataFormatInstance.addInternalColumnDescription("SPLIT_"+parentFeature.getSymbolTable().getName(), parentColumn));
    setSymbolTable(column.getSymbolTable());
//    setSymbolTable(tableHandler.addSymbolTable("SPLIT_"+parentFeature.getSymbolTable().getName(), parentFeature.getSymbolTable()));
  }
View Full Code Here

      } else {
        String items[];
        try {
          items = separatorsPattern.split(symbol);
        } catch (PatternSyntaxException e) {
          throw new FeatureException("The split feature '"+this.toString()+"' could not split the value using the following separators '"+separators+"'",e);
        }
        for (int i = 0; i < items.length; i++) {
          if (items[i].length() > 0) {
            multipleFeatureValue.addFeatureValue(table.addSymbol(items[i]), items[i]);
          }
        }
        multipleFeatureValue.setNullValue(false);
      }
    } else if (value instanceof MultipleFeatureValue) {
      if (((MultipleFeatureValue)value).isNullValue()) {
        multipleFeatureValue.addFeatureValue(parentFeature.getSymbolTable().getSymbolStringToCode(((MultipleFeatureValue)value).getFirstSymbol()), ((MultipleFeatureValue)value).getFirstSymbol());
        multipleFeatureValue.setNullValue(true);
      } else {
        for (String symbol : ((MultipleFeatureValue)value).getSymbols()) {
          String items[];
          try {
            items = separatorsPattern.split(symbol);
          } catch (PatternSyntaxException e) {
            throw new FeatureException("The split feature '"+this.toString()+"' could not split the value using the following separators '"+separators+"'", e);
          }
          for (int i = 0; i < items.length; i++) {
            multipleFeatureValue.addFeatureValue(table.addSymbol(items[i]), items[i]);
          }
          multipleFeatureValue.setNullValue(false);
View Full Code Here

    multipleFeatureValue = new MultipleFeatureValue(this);
  }
 
  public void initialize(Object[] arguments) throws MaltChainedException {
    if (arguments.length != 2) {
      throw new FeatureException("Could not initialize SuffixFeature: number of arguments are not correct. ");
    }
    if (!(arguments[0] instanceof FeatureFunction)) {
      throw new FeatureException("Could not initialize SuffixFeature: the first argument is not a feature. ");
    }
    if (!(arguments[1] instanceof Integer)) {
      throw new FeatureException("Could not initialize SuffixFeature: the second argument is not a string. ");
    }
    setParentFeature((FeatureFunction)arguments[0]);
    setSuffixLength(((Integer)arguments[1]).intValue());
    ColumnDescription parentColumn = dataFormatInstance.getColumnDescriptionByName(parentFeature.getSymbolTable().getName());
    if (parentColumn.getType() != ColumnDescription.STRING) {
      throw new FeatureException("Could not initialize SuffixFeature: the first argument must be a string. ");
    }
    setColumn(dataFormatInstance.addInternalColumnDescription("SUFFIX_"+suffixLength+"_"+parentFeature.getSymbolTable().getName(), parentColumn));
    setSymbolTable(column.getSymbolTable());
//    setSymbolTable(tableHandler.addSymbolTable("SUFFIX_"+suffixLength+"_"+parentFeature.getSymbolTable().getName(), parentFeature.getSymbolTable()));
  }
View Full Code Here

    singleFeatureValue = new SingleFeatureValue(this);
  }
 
  public void initialize(Object[] arguments) throws MaltChainedException {
    if (arguments.length != 2) {
      throw new FeatureException("Could not initialize MergeFeature: number of arguments are not correct. ");
    }
    if (!(arguments[0] instanceof FeatureFunction)) {
      throw new FeatureException("Could not initialize MergeFeature: the first argument is not a feature. ");
    }
    if (!(arguments[1] instanceof FeatureFunction)) {
      throw new FeatureException("Could not initialize MergeFeature: the second argument is not a feature. ");
    }
    setFirstFeature((FeatureFunction)arguments[0]);
    setSecondFeature((FeatureFunction)arguments[1]);
    ColumnDescription firstColumn = (firstFeature.getSymbolTable() != null)?dataFormatInstance.getColumnDescriptionByName(firstFeature.getSymbolTable().getName()):null;
    ColumnDescription secondColumn = (secondFeature.getSymbolTable() != null)?dataFormatInstance.getColumnDescriptionByName(secondFeature.getSymbolTable().getName()):null;
//    if (firstColumn.getType() != secondColumn.getType()) {
//      throw new FeatureException("Could not initialize MergeFeature: the first and the second arguments are not of the same type.");
//    }
//    setColumn(dataFormatInstance.addInternalColumnDescription("MERGE2_"+firstFeature.getSymbolTable().getName()+"_"+secondFeature.getSymbolTable().getName(), firstColumn));

    if (firstFeature.getType() != secondFeature.getType()) {
      throw new FeatureException("Could not initialize MergeFeature: the first and the second arguments are not of the same type.");
    }
    if (firstColumn != null || secondColumn != null) {
      setColumn(dataFormatInstance.addInternalColumnDescription("MERGE2_"+firstFeature.getMapIdentifier()+"_"+secondFeature.getMapIdentifier(), (firstColumn != null)?firstColumn:secondColumn));
    } else {
      setColumn(dataFormatInstance.addInternalColumnDescription("MERGE2_"+firstFeature.getMapIdentifier()+"_"+secondFeature.getMapIdentifier(), ColumnDescription.INPUT, firstFeature.getType(), "", "One"));
View Full Code Here

                  firstInt = Integer.parseInt(firstSymbol);
                } else {
                  firstInt = Integer.parseInt(firstSymbol.substring(0,dotIndex));
                }
              } catch (NumberFormatException e) {
                throw new FeatureException("Could not cast the feature value '"+firstSymbol+"' to integer value.", e);
              }
              String secondSymbol = ((SingleFeatureValue)secondValue).getSymbol();
              dotIndex = secondSymbol.indexOf('.');
              try {
                if (dotIndex == -1) {
                  secondInt = Integer.parseInt(secondSymbol);
                } else {
                  secondInt = Integer.parseInt(secondSymbol.substring(0,dotIndex));
                }
              } catch (NumberFormatException e) {
                throw new FeatureException("Could not cast the feature value '"+secondSymbol+"' to integer value.", e);
              }
              Integer result = firstInt*secondInt;
              singleFeatureValue.setValue(result);
              table.addSymbol(result.toString());
              singleFeatureValue.setSymbol(result.toString());
            } else if (column.getType() == ColumnDescription.REAL) {
              Double firstReal = 0.0;
              Double secondReal = 0.0;
              try {
                firstReal = Double.parseDouble(firstSymbol);
              } catch (NumberFormatException e) {
                throw new FeatureException("Could not cast the feature value '"+firstSymbol+"' to real value.", e);
              }
              String secondSymbol = ((SingleFeatureValue)secondValue).getSymbol();
              try {
                secondReal = Double.parseDouble(secondSymbol);
              } catch (NumberFormatException e) {
                throw new FeatureException("Could not cast the feature value '"+secondSymbol+"' to real value.", e);
              }
              Double result = firstReal*secondReal;
              singleFeatureValue.setValue(result);
              table.addSymbol(result.toString());
              singleFeatureValue.setSymbol(result.toString());
            }
            singleFeatureValue.setNullValue(false);
            singleFeatureValue.setIndexCode(1);
          }
        }
      }
    } else {
      throw new FeatureException("It is not possible to merge Split-features. ");
    }
  }
View Full Code Here

TOP

Related Classes of org.maltparserx.core.feature.FeatureException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.