Skip to content

Commit

Permalink
Work on ispravi.me grammer checker
Browse files Browse the repository at this point in the history
  • Loading branch information
niksedk committed Mar 18, 2018
1 parent 8cd0f47 commit 86db945
Show file tree
Hide file tree
Showing 6 changed files with 484 additions and 31 deletions.
1 change: 0 additions & 1 deletion Haxor/DLL/Logic/Utilities.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Drawing;
using System.Reflection;
using System.Text.RegularExpressions;

Expand Down
30 changes: 18 additions & 12 deletions IspraviMeTranslate/DLL/IspraviError.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;

namespace SubtitleEdit
{
public class IspraviResult
{
public IspraviStatus Status { get; set; }
public IspraviResponse Response { get; set; }
public IspraviStatus status { get; set; }

public IspraviResponse response { get; set; }
}

public class IspraviStatus
{
public string Text { get; set; }
public int Code { get; set; }
public string text { get; set; }
public int code { get; set; }
}
public class IspraviResponse
{
public string Errors { get; set; }
public List<IspraviError> Error { get; set; }
/// <summary>
/// Number of errors
/// </summary>
public int errors { get; set; }

public List<IspraviError> error { get; set; }
}

public class IspraviError
{
public string Suspicious { get; set; }
public string suspicious { get; set; }
public string @class { get; set; }
public int length { get; set; }
public int occurrences { get; set; }
public List<int> position { get; set; }
public List<string> suggestions { get; set; }
}
}
96 changes: 95 additions & 1 deletion IspraviMeTranslate/DLL/IspraviMeApi.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Runtime.Serialization.Json;
Expand All @@ -23,7 +24,7 @@ internal string GetName()

internal string GetUrl()
{
throw new NotImplementedException();
return "https://ispravi.me";
}

internal IspraviResult CheckGrammer(string text, StringBuilder log)
Expand Down Expand Up @@ -67,10 +68,103 @@ internal IspraviResult CheckGrammer(string text, StringBuilder log)
// "response" : null
//}

// example of error result
//{
// "response" : {
// "errors" : 4,
// "error" : [
// {
// "class" : "moderate",
// "length" : 6,
// "position" : [
// 6
// ],
// "suspicious" : "živoat",
// "occurrences" : 1,
// "suggestions" : [
// "života",
// "živost",
// "život",
// "živcat"
// ]
// },
// {
// "position" : [
// 23
// ],
// "length" : 6,
// "class" : "moderate",
// "suggestions" : [
// "buduće"
// ],
// "occurrences" : 1,
// "suspicious" : "buduce"
// },
// {
// "class" : "minor",
// "position" : [
// 0
// ],
// "length" : 5,
// "suggestions" : [
// "Cìlog",
// "eLog",
// "Velog",
// "Clog",
// "Celeg",
// "Celom",
// "Celon",
// "Celox",
// "Belog",
// "Telog"
// ],
// "occurrences" : 1,
// "suspicious" : "Celog"
// },
// {
// "class" : "minor",
// "length" : 7,
// "position" : [
// 13
// ],
// "occurrences" : 1,
// "suggestions" : [
// "vjerujem",
// "vezujem"
// ],
// "suspicious" : "verujem"
// }
// ]
// },
// "request" : {
// "newuser" : true,
// "commonerrors" : false,
// "from" : "undef",
// "session" : "ceada31a0b1f886bd9fc82fdaeb81fd1",
// "contenttype" : "text/plain; charset=UTF-8",
// "remoteip" : "62.44.134.100",
// "contextual" : true,
// "key" : "F2F09D38-2AC3-11E8-8531-4AB7E1FE0083",
// "fixpunctuation" : false,
// "textlength" : 36
// },
// "status" : {
// "code" : 200,
// "time" : 2.422875,
// "href" : null,
// "text" : "OK"
// }
//}
string s = res.Content.ReadAsStringAsync().Result;
Type serializationTargetType = typeof(IspraviResult);
DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(serializationTargetType);
IspraviResult jsonDeserialized = (IspraviResult)jsonSerializer.ReadObject(new MemoryStream(Encoding.UTF8.GetBytes(s)));

// sort by start position
if (jsonDeserialized != null && jsonDeserialized.response != null &&
jsonDeserialized.response.error != null)
jsonDeserialized.response.error = jsonDeserialized.response.error.OrderBy(p => p.position.FirstOrDefault()).ToList();

return jsonDeserialized;
}
else
Expand Down
2 changes: 1 addition & 1 deletion IspraviMeTranslate/DLL/Logic/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static class Utilities
#region StringExtension
public static bool Contains(this string s, char c)
{
return s.Length > 0 && s.IndexOf(c) > 0;
return s.Length > 0 && s.IndexOf(c) >= 0;
}
public static string[] SplitToLines(this string s)
{
Expand Down
Loading

0 comments on commit 86db945

Please sign in to comment.