Skip to content

Commit

Permalink
RU: Adding the file for INlandes rules
Browse files Browse the repository at this point in the history
  • Loading branch information
marigostra committed Jan 24, 2022
1 parent d36f0a2 commit ad5609c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
36 changes: 30 additions & 6 deletions ru/src/main/java/org/luwrain/i18n/ru/SpeakableText.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2012-2021 Michael Pozhidaev <[email protected]>
Copyright 2012-2022 Michael Pozhidaev <[email protected]>
This file is part of LUWRAIN.
Expand All @@ -16,17 +16,18 @@

package org.luwrain.i18n.ru;

import java.io.*;

import org.luwrain.core.*;
import org.luwrain.core.Luwrain.SpeakableTextType;

import org.luwrain.nlp.ru.*;
import org.luwrain.script2.ScriptUtils;
import org.luwrain.script.hooks.*;
import org.luwrain.inlandes.*;
import static org.luwrain.inlandes.Token.*;

final class SpeakableText
{
static private final String
LOG_COMPONENT = Lang.LOG_COMPONENT,
HOOK_PROGRAMMING_PRE = "luwrain.i18n.ru.speakable.programming.pre";

private final HookContainer hookContainer;
Expand All @@ -37,6 +38,7 @@ final class SpeakableText
NullCheck.notNull(hookContainer, "hookContainer");
this.hookContainer = hookContainer;
this.inlandes.loadStandardLibrary();
loadRules();
}

String process(String text, SpeakableTextType type)
Expand All @@ -58,13 +60,35 @@ private String processNatural(String text)
{
NullCheck.notNull(text, "text");
synchronized(inlandes) {
};
return text;
return concat(inlandes.process(text));
}
}

private String processProgramming(String text)
{
NullCheck.notNull(text, "text");
return new TransformerHook(hookContainer).run(HOOK_PROGRAMMING_PRE, text).toString();
}

private void loadRules()
{
try {
try (final BufferedReader r = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("rules"), "UTF-8"))) {
String line = r.readLine();
final StringBuilder b = new StringBuilder();
while (line != null)
{
final String l = line.trim();
if (!l.isEmpty() && l.charAt(0) != '#')
b.append(line).append(System.lineSeparator());
line = r.readLine();
}
inlandes.loadText(new String(b));
}
}
catch(Throwable e)
{
Log.error(LOG_COMPONENT, "unable to load Inlandes rules: " + e.getClass().getName() + ": " + e.getMessage());
}
}
}
2 changes: 2 additions & 0 deletions ru/src/main/resources/org/luwrain/i18n/ru/rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
RULE WHERE до . н '.' . э '.' DO _0 = "до нашей эры";

0 comments on commit ad5609c

Please sign in to comment.