Examples of ArtifactSerializer


Examples of opennlp.tools.util.model.ArtifactSerializer

        }

        String ending = resourceName.substring(lastDot + 1);

        // lookup serializer from map
        ArtifactSerializer serializer = artifactSerializers.get(ending);

        // TODO: Do different? For now just ignore ....
        if (serializer == null)
          continue;

        InputStream resoruceIn = CmdLineUtil.openInFile(resourceFile);

        try {
          resources.put(resourceName, serializer.create(resoruceIn));
        } catch (InvalidFormatException e) {
          // TODO: Fix exception handling
          e.printStackTrace();
        } catch (IOException e) {
          // TODO: Fix exception handling
View Full Code Here

Examples of opennlp.tools.util.model.ArtifactSerializer

        }

        String ending = resourceName.substring(lastDot + 1);

        // lookup serializer from map
        ArtifactSerializer serializer = artifactSerializers.get(ending);

        // TODO: Do different? For now just ignore ....
        if (serializer == null)
          continue;

        InputStream resoruceIn = CmdLineUtil.openInFile(resourceFile);

        try {
          resources.put(resourceName, serializer.create(resoruceIn));
        } catch (InvalidFormatException e) {
          // TODO: Fix exception handling
          e.printStackTrace();
        } catch (IOException e) {
          // TODO: Fix exception handling
View Full Code Here

Examples of opennlp.tools.util.model.ArtifactSerializer

    if (resourcePath != null) {

      Map<String, ArtifactSerializer> artifactSerializers = TokenNameFinderModel
          .createArtifactSerializers();
      List<Element> elements = new ArrayList<Element>();
      ArtifactSerializer serializer = null;


      // TODO: If there is descriptor file, it should be consulted too
      if (featureGenDescriptor != null) {

        InputStream xmlDescriptorIn = CmdLineUtil.openInFile(featureGenDescriptor);

        try {
          artifactSerializers.putAll(GeneratorFactory.extractCustomArtifactSerializerMappings(xmlDescriptorIn));
        } catch (IOException e) {
          // TODO: Improve error handling!
          e.printStackTrace();
        }
        InputStream inputStreamXML = CmdLineUtil.openInFile(featureGenDescriptor);
        try {
          elements = GeneratorFactory.getDescriptorElements(inputStreamXML);
        } catch (IOException e) {
          e.printStackTrace();
        }
      }

      File resourceFiles[] = resourcePath.listFiles();
     
      for (File resourceFile : resourceFiles) {
        String resourceName = resourceFile.getName();
        //gettting the serializer key from the element tag name
        //if the element contains a dict attribute
        for (Element xmlElement : elements) {
          String dictName = xmlElement.getAttribute("dict");
          if (dictName != null && dictName.equals(resourceName)) {
            serializer = artifactSerializers.get(xmlElement.getTagName());
          }
        }
        // TODO: Do different? For now just ignore ....
        if (serializer == null)
          continue;

        InputStream resourceIn = CmdLineUtil.openInFile(resourceFile);

        try {
          resources.put(resourceName, serializer.create(resourceIn));
        } catch (InvalidFormatException e) {
          // TODO: Fix exception handling
          e.printStackTrace();
        } catch (IOException e) {
          // TODO: Fix exception handling
View Full Code Here

Examples of opennlp.tools.util.model.ArtifactSerializer

    return type;
  }

  static HeadRules creaeHeadRules(TrainerToolParams params) throws IOException {

    ArtifactSerializer headRulesSerializer = null;

    if (params.getHeadRulesSerializerImpl() != null) {
      headRulesSerializer = ExtensionLoader.instantiateExtension(ArtifactSerializer.class,
              params.getHeadRulesSerializerImpl());
    }
    else {
      if ("en".equals(params.getLang())) {
        headRulesSerializer = new opennlp.tools.parser.lang.en.HeadRules.HeadRulesSerializer();
      }
      else if ("es".equals(params.getLang())) {
        headRulesSerializer = new opennlp.tools.parser.lang.es.AncoraSpanishHeadRules.HeadRulesSerializer();
      }
      else {
        // default for now, this case should probably cause an error ...
        headRulesSerializer = new opennlp.tools.parser.lang.en.HeadRules.HeadRulesSerializer();
      }
    }

    Object headRulesObject = headRulesSerializer.create(new FileInputStream(params.getHeadRules()));

    if (headRulesObject instanceof HeadRules) {
      return (HeadRules) headRulesObject;
    }
    else {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.