예제 #1
0
        public static ConnectionCostsWriter Build(string filename)
        {
            using (Stream inputStream = new FileStream(filename, FileMode.Open, FileAccess.Read))
            {
                StreamReader streamReader = new StreamReader(inputStream, Encoding.ASCII);

                string   line       = streamReader.ReadLine();
                string[] dimensions = whiteSpaceRegex.Split(line).TrimEnd();

                Debug.Assert(dimensions.Length == 2);

                int forwardSize  = int.Parse(dimensions[0], CultureInfo.InvariantCulture);
                int backwardSize = int.Parse(dimensions[1], CultureInfo.InvariantCulture);

                Debug.Assert(forwardSize > 0 && backwardSize > 0);

                ConnectionCostsWriter costs = new ConnectionCostsWriter(forwardSize, backwardSize);

                while ((line = streamReader.ReadLine()) != null)
                {
                    string[] fields = whiteSpaceRegex.Split(line).TrimEnd();

                    Debug.Assert(fields.Length == 3);

                    int forwardId  = int.Parse(fields[0], CultureInfo.InvariantCulture);
                    int backwardId = int.Parse(fields[1], CultureInfo.InvariantCulture);
                    int cost       = int.Parse(fields[2], CultureInfo.InvariantCulture);

                    costs.Add(forwardId, backwardId, cost);
                }
                return(costs);
            }
        }
예제 #2
0
        public static void Build(DictionaryFormat format,
                                 string inputDirname,
                                 string outputDirname,
                                 string encoding,
                                 bool normalizeEntry)
        {
            Console.WriteLine("building tokeninfo dict...");
            TokenInfoDictionaryBuilder tokenInfoBuilder    = new TokenInfoDictionaryBuilder(format, encoding, normalizeEntry);
            TokenInfoDictionaryWriter  tokenInfoDictionary = tokenInfoBuilder.Build(inputDirname);

            tokenInfoDictionary.Write(outputDirname);
            //tokenInfoDictionary = null; // LUCENENET: IDE0059: Remove unnecessary value assignment
            //tokenInfoBuilder = null; // LUCENENET: IDE0059: Remove unnecessary value assignment
            Console.WriteLine("done");

            Console.WriteLine("building unknown word dict...");
            UnknownDictionaryBuilder unkBuilder    = new UnknownDictionaryBuilder(encoding);
            UnknownDictionaryWriter  unkDictionary = unkBuilder.Build(inputDirname);

            unkDictionary.Write(outputDirname);
            //unkDictionary = null; // LUCENENET: IDE0059: Remove unnecessary value assignment
            //unkBuilder = null; // LUCENENET: IDE0059: Remove unnecessary value assignment
            Console.WriteLine("done");

            Console.WriteLine("building connection costs...");
            ConnectionCostsWriter connectionCosts
                = ConnectionCostsBuilder.Build(inputDirname + System.IO.Path.DirectorySeparatorChar + "matrix.def");

            connectionCosts.Write(outputDirname);
            Console.WriteLine("done");
        }