Uploaded image for project: 'OpenNLP'
  1. OpenNLP
  2. OPENNLP-1161

avoid using concrete tag names of XML config in GeneratorFactory.extractArtifactSerializerMappings()

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Blocker
    • Resolution: Won't Fix
    • 1.8.3
    • None
    • Formats, Name Finder
    • None

    Description

      When working on OPENNLP-1154, I noticed this.

      In GeneratorFactory.extractArtifactSerializerMappings(), it specifies concrete XML tag names:

          for (int i = 0; i < allElements.getLength(); i++) {
            if (allElements.item(i) instanceof Element) {
              Element xmlElement = (Element) allElements.item(i);
      
              String dictName = xmlElement.getAttribute("dict");
              if (dictName != null) {
      
                switch (xmlElement.getTagName()) {
                  case "wordcluster":
                    mapping.put(dictName, new WordClusterDictionary.WordClusterDictionarySerializer());
                    break;
      
                  case "brownclustertoken":
                    mapping.put(dictName, new BrownCluster.BrownClusterSerializer());
                    break;
      
                  case "brownclustertokenclass"://, ;
                    mapping.put(dictName, new BrownCluster.BrownClusterSerializer());
                    break;
      
                  case "brownclusterbigram": //, ;
                    mapping.put(dictName, new BrownCluster.BrownClusterSerializer());
                    break;
      
                  case "dictionary":
                    mapping.put(dictName, new DictionarySerializer());
                    break;
                }
              }
      
              String modelName = xmlElement.getAttribute("model");
              if (modelName != null) {
      
                switch (xmlElement.getTagName()) {
                  case "tokenpos":
                    mapping.put(modelName, new POSModelSerializer());
                    break;
                }
              }
            }
          }
      

      Instead, we'd better let FeatureGeneratorFactories implement a method that returns mapping (Map<String, ArtifactSerializer<?>>) and in GeneratorFactory.extractArtifactSerializerMappings(), the framework just calls the method of FeatureGeneratorFactories, which are found in XML config.

      Attachments

        Issue Links

          Activity

            People

              koji Koji Sekiguchi
              koji Koji Sekiguchi
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: