Example #1
0
        public List <IInfobox> GetInfobox(string wikiText)
        {
            if (string.IsNullOrWhiteSpace(wikiText))
            {
                return(null);
            }

            var result = new List <IInfobox>();

            var buildingName = _titleParserSingle.GetBuildingTitle(wikiText);

            if (string.IsNullOrWhiteSpace(buildingName))
            {
            }

            var buildingIcon = getBuildingIcon(wikiText);

            if (string.IsNullOrWhiteSpace(buildingIcon))
            {
            }

            var buildingType = getBuildingType(wikiText);

            if (buildingType == BuildingType.Unknown)
            {
            }

            var productionInfo = getProductionInfo(wikiText);

            if (productionInfo == null && buildingType == BuildingType.Production)
            {
            }

            var supplyInfo       = getSupplyInfo(wikiText);
            var unlockInfo       = getUnlockInfo(wikiText);
            var buildingSize     = getBuildingSize(wikiText);
            var constructionInfo = getConstructionInfo(wikiText);

            var parsedInfobox = new Infobox
            {
                Name              = buildingName,
                Icon              = buildingIcon,
                Type              = buildingType,
                ProductionInfos   = productionInfo,
                SupplyInfos       = supplyInfo,
                UnlockInfos       = unlockInfo,
                BuildingSize      = buildingSize,
                ConstructionInfos = constructionInfo
                                    //Region
            };

            result.Add(parsedInfobox);

            return(result);
        }
        public List<(string title, string infobox)> ExtractInfobox(string content)
        {
            var result = new List<(string title, string infobox)>();

            if (string.IsNullOrWhiteSpace(content))
            {
                return result;
            }

            var indexInfoboxOldAndNewWorldStart = content.IndexOf(_commons.InfoboxTemplateStartOldAndNewWorld, StringComparison.OrdinalIgnoreCase);
            var indexInfobox2RegionsStart = content.IndexOf(_commons.InfoboxTemplateStart2Regions, StringComparison.OrdinalIgnoreCase);
            var indexInfobox3RegionsStart = content.IndexOf(_commons.InfoboxTemplateStart3Regions, StringComparison.OrdinalIgnoreCase);
            var indexInfoboxStart = content.IndexOf(_commons.InfoboxTemplateStart, StringComparison.OrdinalIgnoreCase);
            var isInfoboxMultiple = false;

            var startIndex = -1;
            if (indexInfoboxOldAndNewWorldStart != -1)
            {
                startIndex = indexInfoboxOldAndNewWorldStart;
            }
            else if (indexInfobox2RegionsStart != -1)
            {
                startIndex = indexInfobox2RegionsStart;
                isInfoboxMultiple = true;
            }
            else if (indexInfobox3RegionsStart != -1)
            {
                startIndex = indexInfobox3RegionsStart;
                isInfoboxMultiple = true;
            }
            else if (indexInfoboxStart != -1)
            {
                //check for multiple infoboxes (only single region)
                var matches = regexMultipleInfoboxes.Matches(content);
                if (matches.Count > 1)
                {
                    foreach (Match curMatch in matches)
                    {
                        var localInfobox = GetInfobox(content, curMatch.Index);
                        var localTitle = _titleParserSingle.GetBuildingTitle(localInfobox);
                        result.Add((localTitle, localInfobox));
                    }

                    return result;
                }

                startIndex = indexInfoboxStart;
            }

            var containsNoKnownTemplateStart = startIndex == -1;
            if (containsNoKnownTemplateStart)
            {
                return result;
            }

            var infobox = GetInfobox(content, startIndex);
            string title = null;
            if (!isInfoboxMultiple)
            {
                title = _titleParserSingle.GetBuildingTitle(infobox);
            }
            result.Add((title, infobox));
            return result;
        }