Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepared to be published in nuget.org #7

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions Andaluh.sln
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,77 @@ EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|ARM = Debug|ARM
Debug|ARM64 = Debug|ARM64
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|ARM = Release|ARM
Release|ARM64 = Release|ARM64
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{25F19C8A-6301-41E7-B127-90387F73ABF6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{25F19C8A-6301-41E7-B127-90387F73ABF6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{25F19C8A-6301-41E7-B127-90387F73ABF6}.Debug|ARM.ActiveCfg = Debug|Any CPU
{25F19C8A-6301-41E7-B127-90387F73ABF6}.Debug|ARM.Build.0 = Debug|Any CPU
{25F19C8A-6301-41E7-B127-90387F73ABF6}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{25F19C8A-6301-41E7-B127-90387F73ABF6}.Debug|ARM64.Build.0 = Debug|Any CPU
{25F19C8A-6301-41E7-B127-90387F73ABF6}.Debug|x64.ActiveCfg = Debug|Any CPU
{25F19C8A-6301-41E7-B127-90387F73ABF6}.Debug|x64.Build.0 = Debug|Any CPU
{25F19C8A-6301-41E7-B127-90387F73ABF6}.Debug|x86.ActiveCfg = Debug|Any CPU
{25F19C8A-6301-41E7-B127-90387F73ABF6}.Debug|x86.Build.0 = Debug|Any CPU
{25F19C8A-6301-41E7-B127-90387F73ABF6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{25F19C8A-6301-41E7-B127-90387F73ABF6}.Release|Any CPU.Build.0 = Release|Any CPU
{25F19C8A-6301-41E7-B127-90387F73ABF6}.Release|ARM.ActiveCfg = Release|Any CPU
{25F19C8A-6301-41E7-B127-90387F73ABF6}.Release|ARM.Build.0 = Release|Any CPU
{25F19C8A-6301-41E7-B127-90387F73ABF6}.Release|ARM64.ActiveCfg = Release|Any CPU
{25F19C8A-6301-41E7-B127-90387F73ABF6}.Release|ARM64.Build.0 = Release|Any CPU
{25F19C8A-6301-41E7-B127-90387F73ABF6}.Release|x64.ActiveCfg = Release|Any CPU
{25F19C8A-6301-41E7-B127-90387F73ABF6}.Release|x64.Build.0 = Release|Any CPU
{25F19C8A-6301-41E7-B127-90387F73ABF6}.Release|x86.ActiveCfg = Release|Any CPU
{25F19C8A-6301-41E7-B127-90387F73ABF6}.Release|x86.Build.0 = Release|Any CPU
{E0097AB9-0B72-4D41-81BB-53D64A282CB1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E0097AB9-0B72-4D41-81BB-53D64A282CB1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E0097AB9-0B72-4D41-81BB-53D64A282CB1}.Debug|ARM.ActiveCfg = Debug|Any CPU
{E0097AB9-0B72-4D41-81BB-53D64A282CB1}.Debug|ARM.Build.0 = Debug|Any CPU
{E0097AB9-0B72-4D41-81BB-53D64A282CB1}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{E0097AB9-0B72-4D41-81BB-53D64A282CB1}.Debug|ARM64.Build.0 = Debug|Any CPU
{E0097AB9-0B72-4D41-81BB-53D64A282CB1}.Debug|x64.ActiveCfg = Debug|Any CPU
{E0097AB9-0B72-4D41-81BB-53D64A282CB1}.Debug|x64.Build.0 = Debug|Any CPU
{E0097AB9-0B72-4D41-81BB-53D64A282CB1}.Debug|x86.ActiveCfg = Debug|Any CPU
{E0097AB9-0B72-4D41-81BB-53D64A282CB1}.Debug|x86.Build.0 = Debug|Any CPU
{E0097AB9-0B72-4D41-81BB-53D64A282CB1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E0097AB9-0B72-4D41-81BB-53D64A282CB1}.Release|Any CPU.Build.0 = Release|Any CPU
{E0097AB9-0B72-4D41-81BB-53D64A282CB1}.Release|ARM.ActiveCfg = Release|Any CPU
{E0097AB9-0B72-4D41-81BB-53D64A282CB1}.Release|ARM.Build.0 = Release|Any CPU
{E0097AB9-0B72-4D41-81BB-53D64A282CB1}.Release|ARM64.ActiveCfg = Release|Any CPU
{E0097AB9-0B72-4D41-81BB-53D64A282CB1}.Release|ARM64.Build.0 = Release|Any CPU
{E0097AB9-0B72-4D41-81BB-53D64A282CB1}.Release|x64.ActiveCfg = Release|Any CPU
{E0097AB9-0B72-4D41-81BB-53D64A282CB1}.Release|x64.Build.0 = Release|Any CPU
{E0097AB9-0B72-4D41-81BB-53D64A282CB1}.Release|x86.ActiveCfg = Release|Any CPU
{E0097AB9-0B72-4D41-81BB-53D64A282CB1}.Release|x86.Build.0 = Release|Any CPU
{3A542431-3F5D-4F90-9151-58B13FE5BBFA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3A542431-3F5D-4F90-9151-58B13FE5BBFA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3A542431-3F5D-4F90-9151-58B13FE5BBFA}.Debug|ARM.ActiveCfg = Debug|Any CPU
{3A542431-3F5D-4F90-9151-58B13FE5BBFA}.Debug|ARM.Build.0 = Debug|Any CPU
{3A542431-3F5D-4F90-9151-58B13FE5BBFA}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{3A542431-3F5D-4F90-9151-58B13FE5BBFA}.Debug|ARM64.Build.0 = Debug|Any CPU
{3A542431-3F5D-4F90-9151-58B13FE5BBFA}.Debug|x64.ActiveCfg = Debug|Any CPU
{3A542431-3F5D-4F90-9151-58B13FE5BBFA}.Debug|x64.Build.0 = Debug|Any CPU
{3A542431-3F5D-4F90-9151-58B13FE5BBFA}.Debug|x86.ActiveCfg = Debug|Any CPU
{3A542431-3F5D-4F90-9151-58B13FE5BBFA}.Debug|x86.Build.0 = Debug|Any CPU
{3A542431-3F5D-4F90-9151-58B13FE5BBFA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3A542431-3F5D-4F90-9151-58B13FE5BBFA}.Release|Any CPU.Build.0 = Release|Any CPU
{3A542431-3F5D-4F90-9151-58B13FE5BBFA}.Release|ARM.ActiveCfg = Release|Any CPU
{3A542431-3F5D-4F90-9151-58B13FE5BBFA}.Release|ARM.Build.0 = Release|Any CPU
{3A542431-3F5D-4F90-9151-58B13FE5BBFA}.Release|ARM64.ActiveCfg = Release|Any CPU
{3A542431-3F5D-4F90-9151-58B13FE5BBFA}.Release|ARM64.Build.0 = Release|Any CPU
{3A542431-3F5D-4F90-9151-58B13FE5BBFA}.Release|x64.ActiveCfg = Release|Any CPU
{3A542431-3F5D-4F90-9151-58B13FE5BBFA}.Release|x64.Build.0 = Release|Any CPU
{3A542431-3F5D-4F90-9151-58B13FE5BBFA}.Release|x86.ActiveCfg = Release|Any CPU
{3A542431-3F5D-4F90-9151-58B13FE5BBFA}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
23 changes: 21 additions & 2 deletions Andaluh/Andaluh.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>8.0</LangVersion>
<OutputType>Library</OutputType>
<StartupObject></StartupObject>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageLicenseExpression>GPL-3.0-or-later</PackageLicenseExpression>
<Authors>Chan ([email protected]) | AndaluGeeks</Authors>
<Company>AndaluGeeks</Company>
<Description>Use this extension to transcript any spanish text to Andaluh</Description>
<Copyright>Copyright (C) AndaluGeeks 2020</Copyright>
<PackageProjectUrl>https://andaluh.es/</PackageProjectUrl>
<RepositoryUrl>https://github.com/andalugeeks/andaluh-net</RepositoryUrl>
<PackageTags>Transliteration, Transcription, Andaluz, Andalu, Andalûh, Andalú</PackageTags>
<Product>Transcriptor Andaluh</Product>
<Version>1.0.3</Version>
<AssemblyVersion>1.0.3.0</AssemblyVersion>
<FileVersion>1.0.3.0</FileVersion>
<PackageReleaseNotes>Downgraded framework version to increase compatibility</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
Expand All @@ -13,4 +27,9 @@
<None Remove="Constants\**" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.1.4" />
<PackageReference Include="Microsoft.Extensions.Options" Version="3.1.4" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion Andaluh/EPA.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Andaluh
{
public static class EPA
{
public static string Transcribe(this string text, string vaf = "VAF", string vvf = "VVF") =>
public static string Transcribe(this string text) =>
text.IsNullOrEmpty() ? string.Empty : new EPAEngine().Transcribe(text);

public static string ToAndaluh(this string text) => text.Transcribe();
Expand Down
2 changes: 0 additions & 2 deletions Andaluh/EPAEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ internal class EPAEngine
new WordInteractionRules()
};



public string Transcribe(string text)
{
var tokenizedString = new TokenEvaluator(text);
Expand Down
4 changes: 2 additions & 2 deletions Andaluh/Extensions/CharExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static char GetVowelTilde(this char vowel)
// If no tilde, replace with circumflex
if (i != -1) return Constants.VOWELS_ALL_TILDE[i];

if (Constants.VOWELS_ALL_TILDE.Contains(vowel)) return vowel;
if (Constants.VOWELS_ALL_TILDE.Contains(vowel.ToString())) return vowel;

return '#';
}
Expand All @@ -23,7 +23,7 @@ public static char GetVowelCircumflex(this char vowel)

if (i != -1) return Constants.VOWELS_ALL_NOTILDE[i + 5];

if (Constants.VOWELS_ALL_TILDE.Contains(vowel)) return vowel;
if (Constants.VOWELS_ALL_TILDE.Contains(vowel.ToString())) return vowel;

return '#';
}
Expand Down
18 changes: 18 additions & 0 deletions Andaluh/Extensions/MatchCollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;

namespace Andaluh.Extensions
{
public static class MatchCollectionExtensions
{
public static bool Any(this MatchCollection matches) => matches.Count != 0;
public static IEnumerable<Match> Where(this MatchCollection matches, Func<Match, bool> func)
{
foreach (Match match in matches)
if (func(match)) yield return match;
}
}
}
47 changes: 30 additions & 17 deletions Andaluh/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,10 @@ public static string ReplaceFirst(this string text, Match match, string replace,

public static string GetWholeWord(this string text, int index)
{
int startIndex, endIndex;
startIndex = text.GetWordStartIndex(index);
endIndex = text.GetWordEndIndex(index);
return text.Substring(startIndex, endIndex - startIndex);
}

public static int GetWordEndIndex(this string text, int index)
{
if (index >= text.Length) return text.Length;
var startIndex = text.GetWordStartIndex(index);
var endIndex = text.GetWordEndIndex(index);

for (int i = index; i < text.Length; i++)
if (Constants.CARACTERES_NO_PALABRA.Any(c => c == text[i])) return i;

return text.Length;
return text.Substring(startIndex, endIndex - startIndex);
}

public static int GetWordStartIndex(this string text, int index)
Expand All @@ -63,18 +53,32 @@ public static int GetWordStartIndex(this string text, int index)
return 0;
}


public static int GetWordEndIndex(this string text, int index)
{
if (index >= text.Length) return text.Length;

for (int i = index; i < text.Length; i++)
if (Constants.CARACTERES_NO_PALABRA.Any(c => c == text[i])) return i;

return text.Length;
}

public static string GetPrefix(this string text, Match match, int bias)
{
var palabra = text.GetWholeWord(match.Index + bias);
var matchIndex = match.Index + bias;
var startIndex = text.GetWordStartIndex(matchIndex);

return palabra.Substring(0, palabra.IndexOf(match.Value));
return text.Substring(startIndex, matchIndex - startIndex);
}

public static string GetSuffix(this string text, Match match, int bias)
{
var palabra = text.GetWholeWord(match.Index + bias);
var matchIndex = match.Index + bias;

var endIndex = text.GetWordEndIndex(matchIndex);

return palabra.Substring(palabra.IndexOf(match.Value) + match.Value.Length);
return text.Substring(matchIndex + match.Value.Length, endIndex - matchIndex - match.Value.Length);
}

public static string KeepCase(this string word, string replacement_word)
Expand Down Expand Up @@ -104,5 +108,14 @@ public static string ReplaceFirstKeepingCase(this string text, string search, st
}

public static bool IsNullOrEmpty(this string str) => str == null || str.Trim().Length == 0;

public static string GetRange(this string text, int start, int end) =>
text.Substring(start, end - start);

public static string GetRangeMinusRight(this string text, int start, int minusEnd) =>
text.Substring(start, text.Length - minusEnd);

public static char GetCharMinusRight(this string text, int minusEnd) =>
text[text.Length - minusEnd];
}
}
5 changes: 3 additions & 2 deletions Andaluh/Rules/Base/Rule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ public string Execute(Dictionary<string, string> dynamicRuleExceptions, string t
return ReplaceMany(text);
}


private string ReplaceMany(string text)
{
var matches = Pattern?.Matches(text);
if (matches?.Any() != true) return text;

var bias = 0;

foreach (Match match in matches.Where(x=>x.Success))
foreach (Match match in matches.Where(x => x.Success))
{
if (NotException(match, text, bias))
{
Expand All @@ -52,7 +53,7 @@ private string ReplaceMany(string text)

private bool NotException(Match match, string text, int bias) => !IsException(text.GetWholeWord(match.Index + bias));

private bool IsException(string palabra) =>
private bool IsException(string palabra) =>
Exceptions?.ContainsKey(palabra.ToLower()) == true ||
DynamicRuleExceptions?.ContainsKey(palabra.ToLower()) == true;

Expand Down
16 changes: 16 additions & 0 deletions Andaluh/Rules/Base/RuleBundle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace Andaluh.Rules.Base
internal abstract class RuleBundle
{
protected readonly Dictionary<string, string> DynamicRuleExceptions;
protected Dictionary<string, string> DelayedAfterRuleDynamicRuleExceptions;
protected abstract IEnumerable<Rule> Rules { get; }

public RuleBundle(Dictionary<string, string> dynamicRuleExceptions = null)
Expand All @@ -14,9 +15,24 @@ public RuleBundle(Dictionary<string, string> dynamicRuleExceptions = null)
public string Execute(string text)
{
foreach (var rule in Rules)
{
DelayedAfterRuleDynamicRuleExceptions = new Dictionary<string, string>();
text = rule.Execute(DynamicRuleExceptions, text);
UpdateDynamicRulesAfterCurrentRule();
}

return text;
}

private void UpdateDynamicRulesAfterCurrentRule()
{
foreach (var exception in DelayedAfterRuleDynamicRuleExceptions)
{
if (!DynamicRuleExceptions.ContainsKey(exception.Key))
DynamicRuleExceptions.Add(exception.Key, exception.Value);
else DynamicRuleExceptions[exception.Key] = exception.Value;
}
}

}
}
9 changes: 9 additions & 0 deletions Andaluh/Rules/Base/RuleConstants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Text.RegularExpressions;

namespace Andaluh.Rules.Base
{
public static class RuleConstants
{
public static readonly Regex pattern_begin_lh = new Regex(@"(?i)\b[aáeéiíoóuú](lh)[aáeéiíoóuú]");
}
}
23 changes: 17 additions & 6 deletions Andaluh/Rules/DigraphRules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,28 @@ internal class DigraphRules : RuleBundle
private static readonly Regex pattern_digraph_special_2 = new Regex("(?i)(tr|p)([ao])(?:ns|st)([bcçdfghjklmnpqstvwxyz])");
private static readonly Regex pattern_digraph_special_3 = new Regex("(?i)([aeiouáéíóú])([bdnr])(s)([bcçdfghjklmnpqstvwxyz])");
private static readonly Regex pattern_digraph_special_4 = new Regex("(?i)([aeiouáéíóú])[djrstxz](l)");
private static readonly Regex pattern_digraph_general = new Regex("(?i)([aeiouáéíóú])(" + string.Join("|", Constants.DIGRAPHS) + ")");
private static readonly Regex pattern_digraph_general = new Regex(@"(?i)([aeiouáéíóú])(" + string.Join("|", Constants.DIGRAPHS) + ")");

private readonly Dictionary<string, string> Digraph_RULES_EXCEPT = new Dictionary<string, string>();
protected override IEnumerable<Rule> Rules => new[]
{
new Rule(pattern_digraph_special_1, digraph_special1_rules_replacer),
new Rule(pattern_digraph_special_2, digraph_special2_rules_replacer),
new Rule(pattern_digraph_special_3, digraph_special3_rules_replacer),
new Rule(pattern_digraph_special_4, digraph_special4_rules_replacer),
new Rule(pattern_digraph_general, digraph_general_rules_replacer)
new Rule(RuleConstants.pattern_begin_lh, exceptuar_patron),
new Rule(pattern_digraph_special_4, digraph_special4_rules_replacer, Digraph_RULES_EXCEPT),
new Rule(pattern_digraph_general, digraph_general_rules_replacer, Digraph_RULES_EXCEPT)
};

private string exceptuar_patron(Match match, string text, int bias)
{
var palabra = text.GetWholeWord(match.Index + bias);
if (!Digraph_RULES_EXCEPT.ContainsKey(palabra))
Digraph_RULES_EXCEPT.Add(palabra, palabra);

return match.Value;
}

private string digraph_special1_rules_replacer(Match match, string text, int bias) =>
match.Value[1] switch
{
Expand All @@ -34,7 +45,7 @@ private string digraph_special2_rules_replacer(Match match, string text, int bia
{
string init_char = match.Groups[1].Value;
char vowel_char = match.Groups[2].Value[0];
char cons_char = match.Groups[0].Value[^1];
char cons_char = match.Groups[0].Value.GetCharMinusRight(1);

return cons_char.ToLower() == 'l' ?
init_char + vowel_char.apply_repl_rules() + cons_char + "-" + cons_char :
Expand All @@ -46,7 +57,7 @@ private string digraph_special3_rules_replacer(Match match, string text, int bia
var vowel_char = match.Value[0].ToString();
var cons_char = match.Value[1].ToString();
var s_char = match.Value[2];
var digraph_char = match.Value[^1];
var digraph_char = match.Value.GetCharMinusRight(1);

return cons_char.ToLower() == "r" && s_char.ToLower() == 's' ?
vowel_char + cons_char + digraph_char + digraph_char :
Expand All @@ -56,7 +67,7 @@ private string digraph_special3_rules_replacer(Match match, string text, int bia
private string digraph_special4_rules_replacer(Match match, string text, int bias)
{
var vowel_char = match.Value[0].ToString();
var digraph_char = match.Value[^1];
var digraph_char = match.Value.GetCharMinusRight(1);

return vowel_char.apply_repl_rules() + digraph_char + "-" + digraph_char;
}
Expand Down
Loading