2021-12-21 13:59:04 +00:00
|
|
|
|
using System.Collections.Generic;
|
2021-12-22 15:17:22 +00:00
|
|
|
|
using System.IO;
|
2021-12-21 13:59:04 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
|
2021-12-22 15:17:22 +00:00
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
2021-12-21 13:59:04 +00:00
|
|
|
|
namespace Frontend.Translations.Tests.Models
|
|
|
|
|
{
|
|
|
|
|
public class SpellCheckResult
|
|
|
|
|
{
|
2021-12-22 15:17:22 +00:00
|
|
|
|
private static Regex wordRegex = new Regex(@"[\p{L}-]+", RegexOptions.Multiline | RegexOptions.Compiled);
|
2021-12-21 17:18:37 +00:00
|
|
|
|
private static Regex regVariables = new Regex("\\{\\{([^\\{].?[^\\}]+)\\}\\}", RegexOptions.Compiled | RegexOptions.Multiline);
|
|
|
|
|
private static Regex htmlTags = new Regex("<[^>]*>", RegexOptions.Compiled | RegexOptions.Multiline);
|
|
|
|
|
private static List<string> trademarks = new List<string>()
|
|
|
|
|
{
|
|
|
|
|
"onlyoffice.com", "onlyoffice.eu", "Office Open XML", "ONLYOFFICE Desktop Editors",
|
|
|
|
|
"ONLYOFFICE Desktop", "ONLYOFFICE Documents", "Google Drive", "Twitter", "Facebook", "LinkedIn", "Google",
|
|
|
|
|
"Yandex", "Yandex.Disk", "Dropbox","OneDrive","ONLYOFFICE", "DocuSign", "e-mail",
|
2021-12-22 15:17:22 +00:00
|
|
|
|
"SharePoint", "Windows Phone", "Enterprise Edition", "AES-256"
|
2021-12-21 17:18:37 +00:00
|
|
|
|
};
|
|
|
|
|
private static List<string> exclusions = new List<string>()
|
|
|
|
|
{
|
|
|
|
|
"ok","doc","docx","xls","xlsx","ppt","pptx","xml","ooxml","jpg","png","mb","ip",
|
|
|
|
|
"canvas","tag","Disk","Box","Dcs","zip","Android","Authenticator","iOS","Windows",
|
2021-12-22 15:17:22 +00:00
|
|
|
|
"Web","oform","WebDAV","kDrive", "Punycode","logo","sms","html","LDAP",
|
2021-12-21 17:18:37 +00:00
|
|
|
|
"Portal","Favicon","URL","QR", "email", "app", "api"
|
|
|
|
|
};
|
2021-12-21 13:59:04 +00:00
|
|
|
|
|
2021-12-22 15:17:22 +00:00
|
|
|
|
private static List<SpellCheckExclude> excludes = File.Exists("../../../spellcheck-excludes.json")
|
|
|
|
|
? JsonConvert.DeserializeObject<List<SpellCheckExclude>>(File.ReadAllText("../../../spellcheck-excludes.json"))
|
|
|
|
|
: new List<SpellCheckExclude>();
|
|
|
|
|
|
|
|
|
|
public SpellCheckResult(string text, string language)
|
2021-12-21 13:59:04 +00:00
|
|
|
|
{
|
|
|
|
|
Text = text;
|
2021-12-22 15:17:22 +00:00
|
|
|
|
Language = language;
|
2021-12-21 13:59:04 +00:00
|
|
|
|
|
2021-12-21 17:18:37 +00:00
|
|
|
|
var sanitizedText = htmlTags.Replace(text, string.Empty);
|
|
|
|
|
|
|
|
|
|
sanitizedText = regVariables.Replace(sanitizedText, string.Empty);
|
|
|
|
|
|
|
|
|
|
foreach (var trademark in trademarks)
|
|
|
|
|
sanitizedText = sanitizedText.Replace(trademark, string.Empty);
|
|
|
|
|
|
2021-12-22 15:17:22 +00:00
|
|
|
|
var lngExcludes = excludes
|
|
|
|
|
.Where(ex => ex.Language == language)
|
|
|
|
|
.SelectMany(ex => ex.Excludes)
|
|
|
|
|
.ToList();
|
|
|
|
|
|
2021-12-21 17:18:37 +00:00
|
|
|
|
Words = wordRegex.Matches(sanitizedText)
|
2021-12-22 15:17:22 +00:00
|
|
|
|
.Select(m => m.Value.Trim('-'))
|
|
|
|
|
.Where(w => !string.IsNullOrEmpty(w)
|
|
|
|
|
&& !exclusions.Exists(t =>
|
|
|
|
|
t.Equals(w, System.StringComparison.InvariantCultureIgnoreCase))
|
|
|
|
|
&& !lngExcludes.Exists(t =>
|
2021-12-21 17:18:37 +00:00
|
|
|
|
t.Equals(w, System.StringComparison.InvariantCultureIgnoreCase)))
|
2021-12-21 13:59:04 +00:00
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
SpellIssues = new List<SpellIssue>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Text { get; }
|
2021-12-22 15:17:22 +00:00
|
|
|
|
public string Language { get; }
|
2021-12-21 13:59:04 +00:00
|
|
|
|
public List<string> Words { get; }
|
|
|
|
|
|
|
|
|
|
public List<SpellIssue> SpellIssues { get; set; }
|
|
|
|
|
|
|
|
|
|
public bool HasProblems
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2021-12-22 15:17:22 +00:00
|
|
|
|
return SpellIssues.Any();
|
2021-12-21 13:59:04 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|