OPENNLP-622 Fixed issues related to command line.
diff --git a/morfologik-addon/src/main/java/opennlp/morfologik/cmdline/builder/XMLDictionaryToTableParams.java b/morfologik-addon/src/main/java/opennlp/morfologik/cmdline/builder/XMLDictionaryToTableParams.java
index b88cc5d..4ee8cd4 100644
--- a/morfologik-addon/src/main/java/opennlp/morfologik/cmdline/builder/XMLDictionaryToTableParams.java
+++ b/morfologik-addon/src/main/java/opennlp/morfologik/cmdline/builder/XMLDictionaryToTableParams.java
@@ -19,6 +19,7 @@
 
 import java.io.File;
 
+import opennlp.tools.cmdline.ArgumentParser.OptionalParameter;
 import opennlp.tools.cmdline.ArgumentParser.ParameterDescription;
 import opennlp.tools.cmdline.params.EncodingParameter;
 
@@ -30,7 +31,15 @@
   @ParameterDescription(valueName = "in", description = "OpenNLP XML Tag Dictionary.")
   File getInputFile();
 
-  @ParameterDescription(valueName = "out", description = "Tab separated format.")
+  @ParameterDescription(valueName = "out", description = "Output for Morfologik (.info will be also created).")
   File getOutputFile();
 
+  @ParameterDescription(valueName = "char", description = "Columm separator (must be a single character)")
+  @OptionalParameter(defaultValue=",")
+  String getSeparator();
+  
+  @ParameterDescription(valueName = "value", description = " Type of lemma-inflected form encoding compression that precedes automaton construction. Allowed values: [suffix, infix, prefix, none].")
+  @OptionalParameter(defaultValue="prefix")
+  String getEncoder();
+  
 }
diff --git a/morfologik-addon/src/main/java/opennlp/morfologik/cmdline/builder/XMLDictionaryToTableTool.java b/morfologik-addon/src/main/java/opennlp/morfologik/cmdline/builder/XMLDictionaryToTableTool.java
index c87f016..0e7f2d5 100644
--- a/morfologik-addon/src/main/java/opennlp/morfologik/cmdline/builder/XMLDictionaryToTableTool.java
+++ b/morfologik-addon/src/main/java/opennlp/morfologik/cmdline/builder/XMLDictionaryToTableTool.java
@@ -23,8 +23,11 @@
 import java.io.IOException;
 import java.nio.charset.Charset;
 import java.nio.file.Files;
+import java.nio.file.Path;
 import java.util.Iterator;
+import java.util.Properties;
 
+import morfologik.stemming.DictionaryMetadata;
 import opennlp.tools.cmdline.BasicCmdLineTool;
 import opennlp.tools.cmdline.CmdLineUtil;
 import opennlp.tools.cmdline.TerminateToolException;
@@ -35,6 +38,8 @@
   interface Params extends XMLDictionaryToTableParams {
   }
 
+  private String SEPARATOR;
+
   public String getShortDescription() {
     return "reads an OpenNLP XML tag dictionary and outputs it in a tab separated file";
   }
@@ -49,6 +54,7 @@
     File dictInFile = params.getInputFile();
     File dictOutFile = params.getOutputFile();
     Charset encoding = params.getEncoding();
+    SEPARATOR = params.getSeparator();
 
     CmdLineUtil.checkInputFile("dictionary input file", dictInFile);
     CmdLineUtil.checkOutputFile("dictionary output file", dictOutFile);
@@ -66,17 +72,56 @@
         encoding)) {
       while (iterator.hasNext()) {
         String word = iterator.next();
-        String wordAndLemma = word + "\t\t"; // lemma is empty
         for (String tag : tagDictionary.getTags(word)) {
-          writer.write(wordAndLemma + tag);
-          writer.newLine();
+          if(valid(word,tag)) {
+            String entry = createEntry(word, tag);
+            writer.write(entry);
+            writer.newLine();
+          }
         }
       }
       writer.close();
+      System.out.println("Created dictionary: " + dictOutFile.toPath());
     } catch (IOException e) {
       throw new TerminateToolException(-1, "Error while writing output: "
           + e.getMessage(), e);
     }
+    
+    Properties info = new Properties();
+    info.setProperty("fsa.dict.separator", SEPARATOR);
+    info.setProperty("fsa.dict.encoding", params.getEncoding().name());
+    info.setProperty("fsa.dict.encoder", params.getEncoder());
+    
+    Path metaPath = DictionaryMetadata.getExpectedMetadataLocation(dictOutFile.toPath());
+    
+    try {
+      info.store(Files.newOutputStream(metaPath), "Info file for FSA Morfologik dictionary.");
+    } catch (IOException e) {
+      throw new TerminateToolException(-1, "Error while writing metadata output: "
+          + e.getMessage(), e);
+    }
+    System.out.println("Created metadata: " + dictOutFile.toPath());
+    
+  }
+
+  private boolean valid(String word, String tag) {
+    if(word.contains(SEPARATOR) || tag.contains(SEPARATOR)) {
+      System.out
+          .println("Warn: invalid entry because contains separator - word: "
+              + word + " tag: " + tag);
+      return false;
+    }
+    
+    return true;
+  }
+
+  private String createEntry(String word, String tag) {
+    
+    String entry = "" + SEPARATOR +// base
+        word + SEPARATOR +
+        tag;
+        
+    return entry;
   }
 
 }
diff --git a/morfologik-addon/src/main/java/opennlp/morfologik/tagdict/MorfologikPOSTaggerFactory.java b/morfologik-addon/src/main/java/opennlp/morfologik/tagdict/MorfologikPOSTaggerFactory.java
index dcb6554..93d6c61 100644
--- a/morfologik-addon/src/main/java/opennlp/morfologik/tagdict/MorfologikPOSTaggerFactory.java
+++ b/morfologik-addon/src/main/java/opennlp/morfologik/tagdict/MorfologikPOSTaggerFactory.java
@@ -17,8 +17,6 @@
 
 package opennlp.morfologik.tagdict;
 
-import static opennlp.morfologik.util.MorfologikUtil.getExpectedPropertiesFile;
-
 import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.FileNotFoundException;
@@ -27,7 +25,6 @@
 import java.io.OutputStream;
 import java.nio.file.Files;
 import java.nio.file.Path;
-import java.nio.file.Paths;
 import java.util.Map;
 
 import morfologik.stemming.DictionaryMetadata;
@@ -81,29 +78,6 @@
   protected void init(Dictionary ngramDictionary, TagDictionary posDictionary) {
     super.init(ngramDictionary, null);
     this.dict = posDictionary;
-
-    // get the dictionary path
-    String path = System.getProperty("morfologik.dict");
-    if (path == null) {
-      throw new IllegalArgumentException(
-          "The property fsa.dict is missing! -Dmorfologik.dict=path");
-    }
-
-    // now we try to load it...
-    try {
-      this.dictData = Files.readAllBytes(Paths.get(path));
-      this.dictInfo = Files.readAllBytes(getExpectedPropertiesFile(path)
-          .toPath());
-
-      this.dict = createMorfologikDictionary(dictData, dictInfo);
-
-    } catch (IllegalArgumentException e) {
-      throw new IllegalArgumentException(
-          "The file is not a Morfologik dictionary!", e);
-    } catch (IOException e) {
-      throw new IllegalArgumentException(
-          "Could not open the Morfologik dictionary or the .info file", e);
-    }
   }
 
   @Override
diff --git a/morfologik-addon/src/test/java/opennlp/morfologik/tagdict/POSTaggerFactoryTest.java b/morfologik-addon/src/test/java/opennlp/morfologik/tagdict/POSTaggerFactoryTest.java
index 9233979..7341a02 100644
--- a/morfologik-addon/src/test/java/opennlp/morfologik/tagdict/POSTaggerFactoryTest.java
+++ b/morfologik-addon/src/test/java/opennlp/morfologik/tagdict/POSTaggerFactoryTest.java
@@ -17,7 +17,7 @@
 
 package opennlp.morfologik.tagdict;
 
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.*;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
@@ -71,6 +71,8 @@
     POSTaggerFactory factory = posModel.getFactory();
     assertTrue(factory.getTagDictionary() instanceof MorfologikTagDictionary);
 
+    factory = null;
+    
     ByteArrayOutputStream out = new ByteArrayOutputStream();
     posModel.serialize(out);
     ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
@@ -79,6 +81,8 @@
 
     factory = fromSerialized.getFactory();
     assertTrue(factory.getTagDictionary() instanceof MorfologikTagDictionary);
+    
+    assertEquals(2, factory.getTagDictionary().getTags("casa").length);
   }
 
 }
\ No newline at end of file