Skip to content

Commit

Permalink
ru: Removing SpeakableTextHook
Browse files Browse the repository at this point in the history
  • Loading branch information
marigostra committed Aug 13, 2021
1 parent 9d6bfff commit f6cf189
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 74 deletions.
2 changes: 1 addition & 1 deletion ru/src/main/java/org/luwrain/i18n/ru/DateUtils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2012-2019 Michael Pozhidaev <[email protected]>
Copyright 2012-2021 Michael Pozhidaev <[email protected]>
This file is part of LUWRAIN.
Expand Down
2 changes: 1 addition & 1 deletion ru/src/main/java/org/luwrain/i18n/ru/Extension.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2012-2019 Michael Pozhidaev <[email protected]>
Copyright 2012-2021 Michael Pozhidaev <[email protected]>
This file is part of LUWRAIN.
Expand Down
6 changes: 5 additions & 1 deletion ru/src/main/java/org/luwrain/i18n/ru/Lang.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2012-2019 Michael Pozhidaev <[email protected]>
Copyright 2012-2021 Michael Pozhidaev <[email protected]>
This file is part of LUWRAIN.
Expand All @@ -19,18 +19,22 @@
import java.util.*;

import org.luwrain.core.*;
import org.luwrain.core.script2.*;
import org.luwrain.i18n.*;
import org.luwrain.nlp.*;

final class Lang extends LangBase
{
private final ScriptCore scriptCore;
private final SpeakableText speakableText;
private final WordList wordsList = new WordList();

Lang(Luwrain luwrain, Map<String, String> staticStrings, Map<String, String> chars)
{
super("ru", luwrain, staticStrings, chars);
NullCheck.notNull(luwrain, "luwrain");
this.scriptCore = new ScriptCore(luwrain);

this.speakableText = new SpeakableText(luwrain);
this.wordsList.loadFromResource();
}
Expand Down
2 changes: 1 addition & 1 deletion ru/src/main/java/org/luwrain/i18n/ru/NumberUtil.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2012-2019 Michael Pozhidaev <[email protected]>
Copyright 2012-2021 Michael Pozhidaev <[email protected]>
This file is part of LUWRAIN.
Expand Down
2 changes: 1 addition & 1 deletion ru/src/main/java/org/luwrain/i18n/ru/RuWord.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2012-2019 Michael Pozhidaev <[email protected]>
Copyright 2012-2021 Michael Pozhidaev <[email protected]>
This file is part of LUWRAIN.
Expand Down
39 changes: 18 additions & 21 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-2020 Michael Pozhidaev <[email protected]>
Copyright 2012-2021 Michael Pozhidaev <[email protected]>
This file is part of LUWRAIN.
Expand All @@ -18,22 +18,24 @@

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

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

final class SpeakableText
{
static private final String HOOK_NATURAL_PRE = "luwrain.i18n.ru.speakable.natural.pre";
static private final String HOOK_NATURAL = "luwrain.i18n.ru.speakable.natural";
static private final String HOOK_PROGRAMMING_PRE = "luwrain.i18n.ru.speech.programming.pre";
static private final String
HOOK_NATURAL_PRE = "luwrain.i18n.ru.speakable.natural.pre",
HOOK_NATURAL = "luwrain.i18n.ru.speakable.natural",
HOOK_PROGRAMMING_PRE = "luwrain.i18n.ru.speech.programming.pre";

private final Luwrain luwrain;
private final HookContainer hookContainer;

SpeakableText(Luwrain luwrain)
SpeakableText(HookContainer hookContainer)
{
NullCheck.notNull(luwrain, "luwrain");
this.luwrain = luwrain;
NullCheck.notNull(hookContainer, "hookContainer");
this.hookContainer = hookContainer;
}

String process(String text, SpeakableTextType type)
Expand All @@ -45,7 +47,7 @@ String process(String text, SpeakableTextType type)
case NATURAL:
return processNatural(text);
case PROGRAMMING:
return processProgramming(text);
return processProgramming(text);
default:
return text;
}
Expand All @@ -54,22 +56,17 @@ String process(String text, SpeakableTextType type)
private String processNatural(String text)
{
NullCheck.notNull(text, "text");
final SpeakableTextHook hook = new SpeakableTextHook(text);
luwrain.runHooks(HOOK_NATURAL_PRE, hook);
String t = hook.getText();
final String t = new TransformerHook(hookContainer).run(HOOK_NATURAL_PRE, text).toString();
final Token[] tokens = ReaderTokenizer.tokenize(t);
final Object tokensRes = new ProviderHook(luwrain).run(HOOK_NATURAL, new Object[]{ScriptUtils.createArray(tokens)});
final Object tokensRes = new ProviderHook(hookContainer).run(HOOK_NATURAL, new Object[]{ScriptUtils.getArray(tokens)});
if (tokensRes != null && tokensRes.toString() != null)
t = tokensRes.toString();
return tokensRes.toString();
return t;
}

private String processProgramming(String text)
private String processProgramming(String text)
{
NullCheck.notNull(text, "text");
final SpeakableTextHook hook = new SpeakableTextHook(text);
luwrain.runHooks(HOOK_PROGRAMMING_PRE, hook);
return hook.getText();
}

return new TransformerHook(hookContainer).run(HOOK_PROGRAMMING_PRE, text).toString();
}
}
47 changes: 0 additions & 47 deletions ru/src/main/java/org/luwrain/i18n/ru/SpeakableTextHook.java

This file was deleted.

2 changes: 1 addition & 1 deletion ru/src/main/java/org/luwrain/i18n/ru/WordList.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2012-2019 Michael Pozhidaev <[email protected]>
Copyright 2012-2021 Michael Pozhidaev <[email protected]>
This file is part of LUWRAIN.
Expand Down

0 comments on commit f6cf189

Please sign in to comment.