Skip to content

Commit

Permalink
More adjective rules and a test for GetAdjective against all major ci…
Browse files Browse the repository at this point in the history
…ties in the world (#360)

* Test GetAdjective against all major cities in the world

* AdjectiveRuleExistsForEveryCountryAndMajorCityInTheWorld

* Rules for Envigado and Nanaimo

* Adjective rule for Chigorodó

* More adjective rules

* Update commonItems.csproj
  • Loading branch information
IhateTrains authored Oct 7, 2023
1 parent 4bd08d6 commit dc26746
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
39 changes: 39 additions & 0 deletions commonItems.UnitTests/Linguistics/StringExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using commonItems.Linguistics;
using Csv;
using FluentAssertions;
using System;
using System.IO;
using System.Linq;
using System.Net;
using Xunit;

namespace commonItems.UnitTests.Linguistics;
Expand Down Expand Up @@ -181,6 +184,13 @@ public class StringExtensionsTests {
[InlineData("Mcif", "Mcifi")]
[InlineData("Maqomo", "Maqomo")]
[InlineData("Frej", "Frejite")]
[InlineData("Trelew", "Trelewense")]
[InlineData("Nanaimo", "Nanaimoite")]
[InlineData("Envigado", "Envigadeño")]
[InlineData("Chigorodó", "Chigorodoseño")]
[InlineData("San Bernardo", "San Bernardino")]
[InlineData("Encantado", "Encantense")]
[InlineData("Lincoln", "Lincolnite")]

// adjectives relying on rewrite rules
[InlineData("Armenia Maioris", "Greater Armenian")]
Expand Down Expand Up @@ -472,6 +482,35 @@ public void CorrectAdjectivesAreGeneratedForNamesFromCsv(string csvFilePath) {
}
}

[Fact]
public void AdjectiveRuleExistsForEveryCountryAndMajorCityInTheWorld() {
var csvUrl = "https://datahub.io/core/world-cities/r/world-cities.csv";
var csv = new WebClient().DownloadString(csvUrl);
var cities = CsvReader.ReadFromText(csv)
.Select(line => line[0])
.Where(city => !string.IsNullOrEmpty(city) && !city.StartsWith("Zürich (Kreis"))
.Distinct()
.ToList();

var countries = CsvReader.ReadFromText(csv)
.Select(line => line[1])
.Where(country => !string.IsNullOrEmpty(country))
.Distinct()
.ToList();

var output = new StringWriter();
Console.SetOut(output);

foreach (var city in cities) {
_ = city.GetAdjective();
}

foreach (var country in countries) {
_ = country.GetAdjective();
}
output.ToString().Should().NotContain("No matching adjective rule found");
}

[Theory]
// ReSharper disable StringLiteralTypo
[InlineData("Vilath#?!", "Vilathian")]
Expand Down
9 changes: 8 additions & 1 deletion commonItems/Linguistics/adjective_rules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@
{"*anon", "*anese"}, // Lebanon
{"*anya", "*anyan"}, // Netanya
{"*aras", "*arentine"}, // Taras
{"*ardo", "*ardino"}, // San Bernardo
{"*aros", "*arian"}, // Paros
{"*atar", "*atari"}, // Qatar
{"*atte", "*atian"}, // Ville Platte
Expand Down Expand Up @@ -235,6 +236,7 @@
{"*etus", "*esian"}, // Miletus
{"*ford", "*fordian"}, // Bedford
{"*furt", "*furter"}, // Frankfurt
{"*gado", "*gadeño"}, // Envigado
{"*gamo", "*gamasque"}, // Bergamo
{"*gano", "*ganese"}, // Lugano
{"*gana", "*ganite"}, // Telangana
Expand Down Expand Up @@ -341,6 +343,7 @@
{"*[c]cis", "*[c]cidian"}, // Chalcis
{"*[c]nai", "*[c]naite"}, // Chennai
{"*[v]ris", "*[v]risian"}, // Marmaris
{"*[v]ado", "*[v]ense"}, // Encantado
{"*[c]ver", "*[c]ver"}, // Denver
{"*[v]ver", "*[v]verian"}, // Hanover

Expand Down Expand Up @@ -407,6 +410,7 @@
{"*ice", "*icean"}, // Nice
{"*ier", "*ieran"}, // Napier
{"*iev", "*ievan"}, // Kiev
{"*imo", "*imoite"}, // Nanaimo
{"*ing", "*ingite"}, // Kuching
{"*ini", "*inian"}, // Leontini
{"*inz", "*inzer"}, // Linz
Expand Down Expand Up @@ -548,6 +552,7 @@
{"*ce", "*cian"}, // Thrace
{"*co", "*can"}, // Morocco
{"*de", "*dean"}, // Cape Verde
{"*dó", "*doseño"}, // Chigorodó
{"*du", "*dunite"}, // Ordu
{"*eh", "*ehi"},
{"*ej", "*ejite"},
Expand All @@ -557,7 +562,8 @@
{"*én", "*enés"}, // Jaén
{"*eo", "*ean"}, // Bengeo
{"*er", "*erite"}, // Casper
{"*es", "*ian"}, // Maldives
{"*es", "*ian"}, // Maldives,
{"*ew", "*ewense"}, // Trelew
{"*ge", "*ginian"}, // Carthage
{"*gh", "*ghian"}, // Middlesbroughian
{"*gk", "*gkan"},
Expand All @@ -581,6 +587,7 @@
{"*ku", "*kuvian"}, // Baku
{"*ld", "*ldian"}, // Chesterfield
{"*ll", "*llese"}, // Marshall
{"*ln", "*lnite"}, // https://en.wikipedia.org/wiki/Lincoln,_Nebraska
{"*lo", "*lonian"}, // Buffalo
{"*lu", "*lan"}, // Honolulu
{"*me", "*man"}, // Rome
Expand Down
2 changes: 1 addition & 1 deletion commonItems/commonItems.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<PackageId>PGCG.$(AssemblyName)</PackageId>
<Version>8.4.1</Version>
<Version>8.4.2</Version>
<Authors>PGCG</Authors>
<PackageProjectUrl>https://github.com/ParadoxGameConverters/commonItems.NET</PackageProjectUrl>
<RepositoryUrl>https://github.com/ParadoxGameConverters/commonItems.NET</RepositoryUrl>
Expand Down

0 comments on commit dc26746

Please sign in to comment.