-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d25cb65
Showing
17 changed files
with
1,132 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# https://editorconfig.org/ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_size = 4 | ||
indent_style = tab | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[**.xml] | ||
indent_size = 2 | ||
indent_style = space |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* text eol=lf | ||
*.png binary |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<manifest:manifest> | ||
<manifest:file-entry manifest:full-path="kukkuniiaat.jar" manifest:media-type="application/vnd.sun.star.uno-component;type=Java" /> | ||
<manifest:file-entry manifest:media-type="application/vnd.sun.star.package-bundle-description" manifest:full-path="description.txt"/> | ||
</manifest:manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<project name="kukkuniiaat" default="all" basedir="."> | ||
<property name="project.src" location="src" /> | ||
<property name="project.build" location="bin" /> | ||
|
||
<target name="all" depends="init, dist" /> | ||
|
||
<target name="init"> | ||
<tstamp /> | ||
<mkdir dir="${project.build}" /> | ||
</target> | ||
|
||
<path id="classpath.libs"> | ||
<fileset dir="lib"> | ||
<include name="*.jar" /> | ||
</fileset> | ||
</path> | ||
|
||
<target name="dist" depends="ooo-build" description="Builds one ZIP for both OpenOffice.org and stand-alone use"> | ||
<zip compress="yes" destfile="Kukkuniiaat.oxt" basedir="." includes="kukkuniiaat.jar,lib/*,lib/foma/*,lib/foma/*/*,description.xml,resources/*.png,META-INF/manifest.xml,description.txt" /> | ||
</target> | ||
|
||
<target name="ooo-build" depends="compile"> | ||
<jar jarfile="kukkuniiaat.jar" basedir="bin"> | ||
<manifest> | ||
<attribute name="RegistrationClassName" value="kukkuniiaat.openoffice.CentralRegistrationClass" /> | ||
<attribute name="RegistrationClasses" value="kukkuniiaat.openoffice.Main" /> | ||
<attribute name="Implementation-Version" value="0.3.1" /> | ||
<attribute name="Class-Path" value=". ./lib/jdom.jar ./lib/juh.jar ./lib/jurt.jar ./lib/ridl.jar ./lib/unoil.jar ./lib/json.jar ./resource" /> | ||
<attribute name="Uno-Type-Path" value="" /> | ||
</manifest> | ||
</jar> | ||
</target> | ||
|
||
<target name="compile" depends="init" description="compile the source " > | ||
<javac srcdir="${project.src}/" | ||
destdir="${project.build}" | ||
nowarn="yes" | ||
depend="yes" | ||
debug="true" | ||
optimize="yes"> | ||
<classpath> | ||
<path refid="classpath.libs" /> | ||
</classpath> | ||
<compilerarg value="-Xlint"/> | ||
</javac> | ||
</target> | ||
|
||
<target name="clean" description="clean up" > | ||
<delete dir="${project.build}" /> | ||
<delete file="kukkuniiaat.jar" /> | ||
<delete file="Kukkuniiaat.oxt" /> | ||
</target> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Kukkuniiaat Spell Checker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<description xmlns="http://openoffice.org/extensions/description/2006" xmlns:d="http://openoffice.org/extensions/description/2006" xmlns:xlink="http://www.w3.org/1999/xlink"> | ||
<identifier value="kukkuniiaat.openoffice.oxt" /> | ||
<display-name> | ||
<name lang="en-US">Kukkuniiaat Spell Checker</name> | ||
<name lang="da-DK">Kukkuniiaat Stavekontrol</name> | ||
<name lang="kl-GL">Kukkuniiaat Stavekontrol</name> | ||
</display-name> | ||
|
||
<version value="0.3.2" /> | ||
|
||
<icon> | ||
<default xlink:href="resources/logo.png" /> | ||
</icon> | ||
|
||
<publisher> | ||
<name xlink:href="http://oqaaserpassualeriffik.org/" lang="en">Oqaaserpassualeriffik</name> | ||
<name xlink:href="http://oqaaserpassualeriffik.org/" lang="da">Oqaaserpassualeriffik</name> | ||
<name xlink:href="http://oqaaserpassualeriffik.org/" lang="kl">Oqaaserpassualeriffik</name> | ||
</publisher> | ||
|
||
<dependencies> | ||
<OpenOffice.org-minimal-version value="3.1.0" d:name="OpenOffice.org 3.1.0" /> | ||
</dependencies> | ||
|
||
<release-notes> | ||
<src xlink:href="CHANGES.txt" lang="en" /> | ||
<src xlink:href="CHANGES.txt" lang="da" /> | ||
<src xlink:href="CHANGES.txt" lang="kl" /> | ||
</release-notes> | ||
|
||
<update-information> | ||
<src xlink:href="http://oqaaserpassualeriffik.org/d/update.xml" /> | ||
</update-information> | ||
</description> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package kukkuniiaat.client; | ||
|
||
public interface ChangeListener { | ||
public void settingsChanged(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,248 @@ | ||
package kukkuniiaat.client; | ||
|
||
import java.security.MessageDigest; | ||
import java.nio.charset.Charset; | ||
import java.net.URL; | ||
import java.util.*; | ||
import java.util.regex.*; | ||
import java.io.*; | ||
|
||
import com.sun.star.lang.Locale; | ||
import com.sun.star.linguistic2.ProofreadingResult; | ||
import com.sun.star.linguistic2.SingleProofreadingError; | ||
|
||
public class Client { | ||
protected Process flookup = null; | ||
protected OutputStream fl_wr = null; | ||
protected InputStream fl_rd = null; | ||
protected Pattern rx = Pattern.compile("(\\S+)"); | ||
protected Matcher rx_m = rx.matcher(""); | ||
protected Pattern rx_pb = Pattern.compile("^\\p{Punct}+(\\S+?)$"); | ||
protected Matcher rx_pb_m = rx_pb.matcher(""); | ||
protected Pattern rx_pe = Pattern.compile("^(\\S+?)\\p{Punct}+$"); | ||
protected Matcher rx_pe_m = rx_pe.matcher(""); | ||
protected Pattern rx_pbe = Pattern.compile("^\\p{Punct}+(\\S+?)\\p{Punct}+$"); | ||
protected Matcher rx_pbe_m = rx_pbe.matcher(""); | ||
protected int position = 0; | ||
protected boolean debug = false; | ||
|
||
public static void main(String args[]) throws Exception { | ||
System.out.println("Initializing client"); | ||
|
||
Client temp = new Client(); | ||
temp.debug = true; | ||
Locale lt = new Locale(); | ||
lt.Language = "kl"; | ||
lt.Country = "GL"; | ||
lt.Variant = "UTF-8"; | ||
|
||
System.out.println("Checking validity of illu: " + temp.isValidWord("illu")); | ||
|
||
ProofreadingResult error = temp.proofreadText("Oqaasileriffiup suliassai pingaarnerit kalaallit naggueqatigiillu oqaasii misissuiffigissallugit taakkulu pillugit paasissutissanik katersuinissaq.", lt, new ProofreadingResult()); | ||
for (int x = 0; x < error.aErrors.length; x++) { | ||
System.out.println(error.aErrors[x].nErrorStart + ", " + error.aErrors[x].nErrorLength + ", " + error.aErrors[x].nErrorType + ", " + error.aErrors[x].aRuleIdentifier + ", " + error.aErrors[x].aShortComment + ", " + error.aErrors[x].aFullComment); | ||
for (int j=0 ; j<error.aErrors[x].aSuggestions.length ; j++) { | ||
System.out.println("\t" + error.aErrors[x].aSuggestions[j]); | ||
} | ||
} | ||
} | ||
|
||
public Client() { | ||
System.err.println("os.name\t" + System.getProperty("os.name")); | ||
System.err.println("os.arch\t" + System.getProperty("os.arch")); | ||
|
||
try { | ||
URL url = null; | ||
if (System.getProperty("os.name").startsWith("Windows")) { | ||
url = getClass().getResource("../../lib/foma/win32/flookup.exe"); | ||
} | ||
else if (System.getProperty("os.name").startsWith("Mac")) { | ||
url = getClass().getResource("../../lib/foma/mac/flookup"); | ||
} | ||
else if (System.getProperty("os.name").startsWith("Linux")) { | ||
if (System.getProperty("os.arch").startsWith("x86_64") || System.getProperty("os.arch").startsWith("amd64")) { | ||
url = getClass().getResource("../../lib/foma/linux64/flookup"); | ||
} | ||
else { | ||
url = getClass().getResource("../../lib/foma/linux32/flookup"); | ||
} | ||
} | ||
// System.err.println(url); | ||
|
||
File flookup_bin = new File(url.toURI()); | ||
if (!flookup_bin.canExecute() && !flookup_bin.setExecutable(true)) { | ||
throw new Exception("Foma's flookup is not executable and could not be made executable!\nTried to execute " + flookup_bin.getCanonicalPath()); | ||
} | ||
|
||
File kal_foma = new File(getClass().getResource("../../lib/foma/kal.foma").toURI()); | ||
if (!kal_foma.canRead()) { | ||
throw new Exception("kal.foma is not readable!"); | ||
} | ||
|
||
// This extension currently only works on Windows, Mac OS X on Intel, Linux x86, and Linux x86_64/amd64. | ||
ProcessBuilder pb = new ProcessBuilder(flookup_bin.getAbsolutePath(), "-b", "-x", kal_foma.getAbsolutePath()); | ||
Map<String,String> env = pb.environment(); | ||
env.put("CYGWIN", "nodosfilewarning"); | ||
// pb.redirectError(ProcessBuilder.Redirect.INHERIT); | ||
// System.err.println(pb.command()); | ||
flookup = pb.start(); | ||
|
||
fl_wr = flookup.getOutputStream(); | ||
fl_rd = flookup.getInputStream(); | ||
} | ||
catch (Exception ex) { | ||
showError(ex); | ||
} | ||
} | ||
|
||
synchronized public ProofreadingResult proofreadText(final String paraText, final Locale locale, ProofreadingResult paRes) { | ||
try { | ||
paRes.nStartOfSentencePosition = position; | ||
paRes.nStartOfNextSentencePosition = position + paraText.length(); | ||
paRes.nBehindEndOfSentencePosition = paRes.nStartOfNextSentencePosition; | ||
|
||
ArrayList<SingleProofreadingError> errors = new ArrayList<SingleProofreadingError>(); | ||
|
||
rx_m.reset(paraText); | ||
while (rx_m.find()) { | ||
SingleProofreadingError err = processWord(rx_m.group(), rx_m.start()); | ||
if (err != null) { | ||
errors.add(err); | ||
} | ||
} | ||
|
||
paRes.aErrors = errors.toArray(paRes.aErrors); | ||
} | ||
catch (final Throwable t) { | ||
showError(t); | ||
paRes.nBehindEndOfSentencePosition = paraText.length(); | ||
} | ||
return paRes; | ||
} | ||
|
||
synchronized public boolean isValid(final String word) { | ||
if (flookup == null || fl_wr == null || fl_rd == null) { | ||
return false; | ||
} | ||
|
||
if (isValidWord(word)) { | ||
// System.err.println(word + " valid"); | ||
return true; | ||
} | ||
|
||
String lword = word.toLowerCase(); | ||
if (!word.equals(lword) && isValidWord(lword)) { | ||
// System.err.println(word + " valid as lower case"); | ||
return true; | ||
} | ||
|
||
rx_pe_m.reset(word); | ||
if (rx_pe_m.matches()) { | ||
if (isValidWord(rx_pe_m.group(1))) { | ||
// System.err.println(word + " valid with ending punctuation stripped"); | ||
return true; | ||
} | ||
if (isValidWord(rx_pe_m.group(1).toLowerCase())) { | ||
// System.err.println(word + " valid with ending punctuation stripped and lower cased"); | ||
return true; | ||
} | ||
} | ||
|
||
rx_pb_m.reset(word); | ||
if (rx_pb_m.matches()) { | ||
if (isValidWord(rx_pb_m.group(1))) { | ||
// System.err.println(word + " valid with starting punctuation stripped"); | ||
return true; | ||
} | ||
if (isValidWord(rx_pb_m.group(1).toLowerCase())) { | ||
// System.err.println(word + " valid with starting punctuation stripped and lower cased"); | ||
return true; | ||
} | ||
} | ||
|
||
rx_pbe_m.reset(word); | ||
if (rx_pbe_m.matches()) { | ||
if (isValidWord(rx_pbe_m.group(1))) { | ||
// System.err.println(word + " valid with starting punctuation stripped"); | ||
return true; | ||
} | ||
if (isValidWord(rx_pbe_m.group(1).toLowerCase())) { | ||
// System.err.println(word + " valid with starting punctuation stripped and lower cased"); | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
protected SingleProofreadingError processWord(final String word, final int start) { | ||
if (debug) { | ||
System.err.println(word + "\t" + start); | ||
} | ||
|
||
if (isValid(word)) { | ||
return null; | ||
} | ||
|
||
SingleProofreadingError err = new SingleProofreadingError(); | ||
err.nErrorStart = start; | ||
err.nErrorLength = word.length(); | ||
err.nErrorType = 1; | ||
return err; | ||
} | ||
|
||
public boolean isValidWord(String word) { | ||
word = word + "\n"; | ||
byte[] res = new byte[4]; | ||
try { | ||
// System.err.println("Sending data " + word); | ||
fl_wr.write(word.getBytes(Charset.forName("UTF-8"))); | ||
fl_wr.flush(); | ||
// System.err.println("Sent data " + word); | ||
if (fl_rd.read(res, 0, 4) != 4) { | ||
throw new Exception("Failed to read first 4 bytes from flookup!"); | ||
} | ||
// System.err.println("Read data " + new String(res, Charset.forName("UTF-8"))); | ||
int avail = fl_rd.available(); | ||
byte[] res2 = new byte[4+avail]; | ||
System.arraycopy(res, 0, res2, 0, 4); | ||
res = res2; | ||
if (fl_rd.read(res2, 4, avail) != avail) { | ||
throw new Exception("Failed to read first 4 bytes from flookup!"); | ||
} | ||
// System.err.println("Read data " + new String(res, Charset.forName("UTF-8"))); | ||
} | ||
catch (Exception ex) { | ||
showError(ex); | ||
return false; | ||
} | ||
|
||
return res[0] != '+' || res[1] != '?' || res[2] != '\n'; | ||
} | ||
|
||
static void showError(final Throwable e) { | ||
kukkuniiaat.openoffice.Main.showError(e); | ||
} | ||
|
||
public static String makeHash(byte[] convertme) { | ||
MessageDigest md = null; | ||
try { | ||
md = MessageDigest.getInstance("SHA-1"); | ||
} | ||
catch (final Throwable t) { | ||
} | ||
try { | ||
md = MessageDigest.getInstance("MD5"); | ||
} | ||
catch (final Throwable t) { | ||
} | ||
return byteArray2Hex(md.digest(convertme)); | ||
} | ||
|
||
private static String byteArray2Hex(final byte[] hash) { | ||
Formatter formatter = new Formatter(); | ||
for (byte b : hash) { | ||
formatter.format("%02x", b); | ||
} | ||
return formatter.toString(); | ||
} | ||
} |
Oops, something went wrong.