예제 #1
0
 // TODO: this should use inputstreams from the loader, not File!
 public virtual void Inform(IResourceLoader loader)
 {
     if (mapping != null)
     {
         IList <string> wlist = null;
         if (File.Exists(mapping))
         {
             wlist = new List <string>(GetLines(loader, mapping));
         }
         else
         {
             var files = SplitFileNames(mapping);
             wlist = new List <string>();
             foreach (string file in files)
             {
                 var lines = GetLines(loader, file.Trim());
                 wlist.AddRange(lines);
             }
         }
         NormalizeCharMap.Builder builder = new NormalizeCharMap.Builder();
         ParseRules(wlist, builder);
         m_normMap = builder.Build();
         if (m_normMap.map == null)
         {
             // if the inner FST is null, it means it accepts nothing (e.g. the file is empty)
             // so just set the whole map to null
             m_normMap = null;
         }
     }
 }
예제 #2
0
 protected virtual void ParseRules(IList <string> rules, NormalizeCharMap.Builder builder)
 {
     foreach (string rule in rules)
     {
         Match m = p.Match(rule);
         if (!m.Success)
         {
             throw new System.ArgumentException("Invalid Mapping Rule : [" + rule + "], file = " + mapping);
         }
         builder.Add(ParseString(m.Groups[1].Value), ParseString(m.Groups[2].Value));
     }
 }