예제 #1
0
        public static TransferItem[] BuildInfoArray(string xml, string system, string body, string custom, string category, string coords, List<string> archiveNames)
        {
            XmlSerializer ser = new XmlSerializer(typeof(TransferItem[]));
            StringReader reader = new StringReader(xml);
            TransferItem[] items = ser.Deserialize(reader) as TransferItem[];
            SystemCoordinates sc = ParseCoordinateValues(coords);

            foreach (TransferItem item in items)
            {
                if (item.Name == WellKnownItems.Headline && item.Values.Count > 0)
                {
                    item.Values[0].Text = system + " " + body;
                    item.Values[0].Value = double.NaN;
                    break;
                }
            }

            List<TransferItem> info = new List<TransferItem>();
            TransferItem ti = new TransferItem();
            ti.Name = WellKnownItems.System;
            ti.Values = new List<TransferItemValue>(new TransferItemValue[] { new TransferItemValue() });
            ti.Values[0].Text = system;
            ti.Values[0].Value = double.NaN;
            info.Add(ti);
            ti = new TransferItem();
            ti.Name = WellKnownItems.BodyCode;
            ti.Values = new List<TransferItemValue>(new TransferItemValue[] { new TransferItemValue() });
            ti.Values[0].Text = body;
            ti.Values[0].Value = double.NaN;
            info.Add(ti);

            ti = new TransferItem();
            ti.Name = WellKnownItems.GalCoordX;
            ti.Values = new List<TransferItemValue>(new TransferItemValue[] { new TransferItemValue() });
            ti.Values[0].Text = "";
            ti.Values[0].Value = sc.X;
            info.Add(ti);
            ti = new TransferItem();
            ti.Name = WellKnownItems.GalCoordY;
            ti.Values = new List<TransferItemValue>(new TransferItemValue[] { new TransferItemValue() });
            ti.Values[0].Text = "";
            ti.Values[0].Value = sc.Y;
            info.Add(ti);
            ti = new TransferItem();
            ti.Name = WellKnownItems.GalCoordZ;
            ti.Values = new List<TransferItemValue>(new TransferItemValue[] { new TransferItemValue() });
            ti.Values[0].Text = "";
            ti.Values[0].Value = sc.Z;
            info.Add(ti);

            ti = new TransferItem();
            ti.Name = WellKnownItems.CustomCategory;
            ti.Values = new List<TransferItemValue>(new TransferItemValue[] { new TransferItemValue() });
            ti.Values[0].Text = category.Replace(Environment.NewLine, ";");
            ti.Values[0].Value = double.NaN;
            info.Add(ti);
            ti = new TransferItem();
            ti.Name = WellKnownItems.CustomDescription;
            ti.Values = new List<TransferItemValue>(new TransferItemValue[] { new TransferItemValue() });
            ti.Values[0].Text = custom;
            ti.Values[0].Value = double.NaN;
            info.Add(ti);
            if (archiveNames.Count > 0)
            {
                ti = new TransferItem();
                ti.Name = WellKnownItems.ArchiveName;
                ti.Values = new List<TransferItemValue>();
                foreach (string name in archiveNames)
                {
                    TransferItemValue tiv = new TransferItemValue();
                    tiv.Text = name;
                    tiv.Value = double.NaN;
                    ti.Values.Add(tiv);
                }
                info.Add(ti);
            }
            foreach (TransferItem item in items)
            {
                if (item == null)
                {
                    continue;
                }
                if (item.Name != "DELIMITER")
                {
                    info.Add(item);
                }
            }
            return info.ToArray();
        }
예제 #2
0
        private TransferItem ReadTableItem(Bytemap imageGray, Bytemap imageBinary, Bytemap imageBinarySplit, List<Line> left, List<Line> right)
        {
            List<Rectangle> allLeft = new List<Rectangle>();
            foreach (Line line in left)
            {
                allLeft.AddRange(line);
            }
            string leftText = "";
                for (int i = 0; i < allLeft.Count; i++)
                {
                    if (i > 0 && ImageLetters.IsNewWord(allLeft, i, false))
                    {
                        leftText += " ";
                    }
                    leftText += PredictAsLetter(imageGray, imageBinary, allLeft[i]);
                }

            TableItem item = GetTableItem(leftText);
            if (item == null)
            {
                return null;
            }
            if (RawMode)
            {
                item.Name = leftText;
            }

            TransferItem ti = new TransferItem(item.Name);
            for (int i = 0; i < right.Count; i++)
            {
                TransferItemValue tv = new TransferItemValue();
                List<Rectangle> rightLine = new List<Rectangle>(right[i]);
                if (rightLine.Count == 0) continue;

                if (item.InitialSkip > 0)
                {
                    rightLine.RemoveRange(0, Math.Min(item.InitialSkip, rightLine.Count));
                }

                int numberLength = GetNumberLength(rightLine, item);
                string accumulateText = "";
                string accumulateNumber = "";
                for (int j = 0; j < rightLine.Count; j++)
                {
                    if (accumulateText != "" && ImageLetters.IsNewWord(rightLine, j, false))
                    {
                        accumulateText += " ";
                    }
                    // Test if in range for numerical or for text portion.
                    if (j < numberLength)
                    {
                        if (j == 0 && rightLine[j].Width > 10)
                        {
                            // Extra splittish to get any "-" separated from the digit.
                            accumulateNumber += PredictAsNumber(imageGray, imageBinarySplit, rightLine[j]);
                        }
                        else
                        {
                            accumulateNumber += PredictAsNumber(imageGray, imageBinary, rightLine[j]);
                        }
                    }
                    else
                    {
                        // Reading part of text information: Read as letter.
                        accumulateText += PredictAsLetter(imageGray, imageBinary, rightLine[j]);
                    }
                }
                if (accumulateNumber != "")
                {
                    tv.Value = GetNumericalValue(accumulateNumber, item.Percentage);
                }
                else
                {
                    tv.Value = float.NaN;
                }
                if (accumulateText != "")
                {
                    tv.Text = SimilarityMatch.GuessWords(accumulateText, wordList);
                }
                if (RawMode)
                {
                    tv.Text = accumulateNumber + accumulateText;
                }
                tv.Unit = item.Unit;
                if (item.NoText)
                {
                    tv.Text = "";
                }
                // Special case of '<' in age table item. Don't know how to handle this systematically yet.
                if (item.Name == "AGE" && accumulateText.Split(new char[] { ' ' }).Length == 3)
                {
                    tv.Value = 0;
                }
                ti.Values.Add(tv);
            }

            return ti;
        }
예제 #3
0
        private TransferItem GuessMiningReserves(string mining)
        {
            TransferItem ti = new TransferItem("MINING_RESERVES");

            mining = mining.Replace("y", "j");
            mining = mining.Replace("reseaes", "reserves");
            for (int i = 0; i < itemConfig.MiningReserves.Length; i++)
            {
                if (SimilarityMatch.WordsSimilar(mining, itemConfig.MiningReserves[i]))
                {
                    TransferItemValue tv = new TransferItemValue();
                    tv.Text = itemConfig.MiningReserves[i];
                    tv.Value = float.NaN;
                    ti.Values.Add(tv);                 
                    return ti;
                }
            }
            return null;
        }
예제 #4
0
        private TransferItem GuessTerraforming(string terraforming)
        {
            TransferItem ti = new TransferItem("TERRAFORMING");

            for (int i = 0; i < itemConfig.Terraforming.Length; i++)
            {
                if (SimilarityMatch.WordsSimilar(terraforming, itemConfig.Terraforming[i]))
                {
                    TransferItemValue tv = new TransferItemValue();
                    tv.Text = itemConfig.Terraforming[i];
                    tv.Value = float.NaN;
                    ti.Values.Add(tv);
                    return ti;
                }
            }

            string[] tf = terraforming.Split(new char[] { ' ' });
            if (SimilarityMatch.WordsSimilar(tf[tf.Length - 1], "terraforming"))
            {
                TransferItemValue tv = new TransferItemValue();
                tv.Text = itemConfig.Terraforming[0];
                tv.Value = float.NaN;
                ti.Values.Add(tv);
                return ti;
            }
            if (SimilarityMatch.WordsSimilar(tf[tf.Length - 1], "terraformed"))
            {
                TransferItemValue tv = new TransferItemValue();
                tv.Text = itemConfig.Terraforming[0];
                tv.Value = float.NaN;
                ti.Values.Add(tv);
                return ti;
            }
            return null;
        }
예제 #5
0
        private TransferItem ReadDescription(TextSection desc, Bytemap imageGray, Bytemap imageBinary)
        {
            string description = "";
            List<Rectangle> all = new List<Rectangle>();
            for (int i = 0; i < desc.Count; i++)
            {
                all.AddRange(desc[i]);
            }

            for (int i = 0; i < all.Count; i++)
            {
                if (i > 0 && ImageLetters.IsNewWord(all, i, true))
                {
                    description += " ";
                }
                description += PredictAsLetterD(imageGray, imageBinary, all[i]);
            }
            TransferItem ti = new TransferItem(WellKnownItems.Description);
            TransferItemValue tv = new TransferItemValue();
            if (!RawMode)
            {
                tv.Text = GuessDescription(description);
            }
            else
            {
                tv.Text = description;
            }
            tv.Value = float.NaN;
            ti.Values.Add(tv);
            return ti;
        }
예제 #6
0
        private TransferItem ReadTableItem(Bytemap imageGray, Bytemap imageBinary, Bytemap imageBinarySplit, List<Line> left, List<Line> right)
        {
            List<Rectangle> allLeft = new List<Rectangle>();
            int lettersRight = 0;
            foreach (Line line in right)
            {
                lettersRight += line.Count;
            }

            if (lettersRight > 0 || left.Count <= 1)
            {
                foreach (Line line in left)
                {
                    allLeft.AddRange(line);
                }
            }
            else
            {
                allLeft.AddRange(left[0]);
                for (int i = left.Count - 1; i >= 1; i--)
                {
                    right.Insert(0, left[i]);
                }
            }

            string leftText = "";
                for (int i = 0; i < allLeft.Count; i++)
                {
                    if (i > 0 && ImageLetters.IsNewWord(allLeft, i, false))
                    {
                        leftText += " ";
                    }
                    leftText += PredictAsLetter(imageGray, imageBinary, allLeft[i]);
                }

            TableItem item = GetTableItem(leftText);
            if (item == null)
            {
                return null;
            }
            if (RawMode)
            {
                item.Name = leftText;
            }

            TransferItem ti = new TransferItem(item.Name);
            for (int i = 0; i < right.Count; i++)
            {
                TransferItemValue tv = new TransferItemValue();
                List<Rectangle> rightLine = new List<Rectangle>(right[i]);
                if (rightLine.Count == 0) continue;

                if (item.InitialSkip > 0)
                {
                    rightLine.RemoveRange(0, Math.Min(item.InitialSkip, rightLine.Count));
                }

                int numberLength = GetNumberLength(rightLine, item);
                string accumulateText = "";
                string accumulateNumber = "";
                for (int j = 0; j < rightLine.Count; j++)
                {
                    if (accumulateText != "" && ImageLetters.IsNewWord(rightLine, j, false))
                    {
                        accumulateText += " ";
                    }
                    // Test if in range for numerical or for text portion.
                    if (j < numberLength)
                    {
                        if (j == 0 && rightLine[j].Width > 10)
                        {
                            // Extra splittish to get any "-" separated from the digit.
                            accumulateNumber += PredictAsNumber(imageGray, imageBinarySplit, rightLine[j]);
                        }
                        else
                        {
                            accumulateNumber += PredictAsNumber(imageGray, imageBinary, rightLine[j]);
                        }
                    }
                    else
                    {
                        // Reading part of text information: Read as letter.
                        accumulateText += PredictAsLetter(imageGray, imageBinary, rightLine[j]);
                    }
                }

                // TODO: Eliminate this hack. Should be a configurable flag in TableItem class.
                if (item.Name == "AGE" || item.Name == "RADIUS")
                {
                    // Never has a decimal point, so the decimal point is most likely a ','
                    int indexDec = accumulateNumber.IndexOf('.');
                    if (indexDec >= 0 && accumulateNumber.IndexOf(',') < 0)
                    {
                        accumulateNumber = accumulateNumber.Substring(0, indexDec) + accumulateNumber.Substring(indexDec + 1);
                    }
                }
                if (item.Name == "ORBIT_PERIAPSIS")
                {
                    if (Math.Abs(GetNumericalValue(accumulateNumber, item.Percentage)) > 360)
                    {
                        accumulateNumber =  accumulateNumber.Replace(',', '.');
                    }
                }

                if (accumulateNumber != "")
                {
                    tv.Value = GetNumericalValue(accumulateNumber, item.Percentage);
                }
                else
                {
                    tv.Value = float.NaN;
                }
                if (accumulateText != "")
                {
                    tv.Text = SimilarityMatch.GuessWords(accumulateText, wordList);
                }
                if (RawMode)
                {
                    tv.Text = accumulateNumber + accumulateText;
                }
                tv.Unit = item.Unit;
                if (item.NoText)
                {
                    tv.Text = "";
                }
                // Special case of '<' in age table item. Don't know how to handle this systematically yet.
                if (item.Name == "AGE" && accumulateText.Split(new char[] { ' ' }).Length == 3)
                {
                    tv.Value = 0;
                }
                ti.Values.Add(tv);
            }

            return ti;
        }