Skip to content

Commit

Permalink
Adding SpellText
Browse files Browse the repository at this point in the history
  • Loading branch information
marigostra committed Jun 10, 2022
1 parent 3c90528 commit 06768e9
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 46 deletions.
34 changes: 34 additions & 0 deletions src/main/java/org/luwrain/controls/EditSpellChecking.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
Copyright 2012-2022 Michael Pozhidaev <[email protected]>
This file is part of LUWRAIN.
LUWRAIN is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
LUWRAIN is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
*/

package org.luwrain.controls;

import java.util.*;

import org.luwrain.core.*;
import static org.luwrain.controls.EditUtils.*;

public class EditSpellChecking implements EditArea.ChangeListener
{
@Override public void onEditChange(EditArea editArea, MarkedLines lines, HotPoint hotPoint)
{
final SortedMap<Integer, String> text = new TreeMap<>();
blockBounds(editArea, hotPoint.getHotPointY(),(line, marks)->(!line.trim().isEmpty()),
(lines_, index)->text.put(index, lines.getLine(index)));
}


}
15 changes: 15 additions & 0 deletions src/main/java/org/luwrain/nlp/RomanNum.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
Copyright 2012-2022 Michael Pozhidaev <[email protected]>
This file is part of LUWRAIN.
LUWRAIN is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
LUWRAIN is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
*/

package org.luwrain.nlp;

Expand Down
25 changes: 25 additions & 0 deletions src/main/java/org/luwrain/nlp/SpellChecker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
Copyright 2012-2022 Michael Pozhidaev <[email protected]>
This file is part of LUWRAIN.
LUWRAIN is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
LUWRAIN is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
*/

package org.luwrain.nlp;

import java.util.*;


public interface SpellChecker
{
List<SpellProblem> check(String text);
}
23 changes: 23 additions & 0 deletions src/main/java/org/luwrain/nlp/SpellProblem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
Copyright 2012-2022 Michael Pozhidaev <[email protected]>
This file is part of LUWRAIN.
LUWRAIN is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
LUWRAIN is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
*/

package org.luwrain.nlp;

public interface SpellProblem
{
String getComment();
String getShortComment();
}
63 changes: 63 additions & 0 deletions src/main/java/org/luwrain/nlp/SpellText.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
Copyright 2012-2022 Michael Pozhidaev <[email protected]>
This file is part of LUWRAIN.
LUWRAIN is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
LUWRAIN is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
*/

package org.luwrain.nlp;

import java.util.*;

public class SpellText
{
final String text;
private final List<Fragment> fragments = new ArrayList<>();
private List<SpellProblem> problems;

public SpellText(String[] text, SpellChecker checker)
{
if (text.length == 0)
{
this.text = "";
return;
}
if (text.length == 1)
{
this.text = text[0];
fragments.add(new Fragment(0, text[0].length()));
return;
}
final StringBuilder b = new StringBuilder();
b.append(text[0]);
fragments.add(new Fragment(0, b.length()));
for(int i = 1;i < text.length;i++)
{
fragments.add(new Fragment(b.length() + 1, b.length() + text[i].length() + 1));
b.append(" ").append(text[i]);
}
this.text = new String(b);
if (fragments.size() != text.length)
throw new IllegalStateException("the fragments and text arrays have different length");
this.problems = checker.check(this.text);
}

static public final class Fragment
{
final int posFrom, posTo;
Fragment(int posFrom, int posTo)
{
this.posFrom = posFrom;
this.posTo = posTo;
}
}
}
44 changes: 0 additions & 44 deletions src/main/java/org/luwrain/nlp/ru/spell/SpellChecker.java

This file was deleted.

2 changes: 1 addition & 1 deletion src/test/java/org/luwrain/io/download/TaskTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2012-2020 Michael Pozhidaev <[email protected]>
Copyright 2012-2022 Michael Pozhidaev <[email protected]>
This file is part of LUWRAIN.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2012-2018 Michael Pozhidaev <[email protected]>
Copyright 2012-2022 Michael Pozhidaev <[email protected]>
This file is part of LUWRAIN.
Expand Down

0 comments on commit 06768e9

Please sign in to comment.