forked from LaurensWeyn/Spark-Reader
-
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.
Re-add old deconjugator's validity test
- Loading branch information
Showing
12 changed files
with
431 additions
and
224 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,84 @@ | ||
/* | ||
* Copyright (C) 2017 Laurens Weyn | ||
* | ||
* This program 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. | ||
* | ||
* This program 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. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package language.deconjugator; | ||
|
||
import language.dictionary.DefTag; | ||
import language.dictionary.Definition; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
/** | ||
* Holds a possible valid conjugation if a word exists with the valid tags | ||
* @author Laurens Weyn | ||
*/ | ||
public abstract class AbstractWord | ||
{ | ||
protected String word, originalWord; | ||
protected Set<DefTag> neededTags; | ||
protected String process; | ||
|
||
public AbstractWord(String originalWord, String word, Set<DefTag> neededTags, String process) | ||
{ | ||
this.originalWord = originalWord; | ||
this.word = word; | ||
this.neededTags = neededTags; | ||
this.process = process.trim(); | ||
} | ||
public AbstractWord(String word, String process) | ||
{ | ||
this.originalWord = word; | ||
this.word = word; | ||
this.neededTags = new HashSet<>(); | ||
this.process = process; | ||
} | ||
public String getOriginalWord() | ||
{ | ||
return originalWord; | ||
} | ||
public String getWord() | ||
{ | ||
return word; | ||
} | ||
|
||
public Set<DefTag> getNeededTags() | ||
{ | ||
return neededTags; | ||
} | ||
|
||
abstract public boolean defMatches(Definition def); | ||
|
||
public String getProcess() | ||
{ | ||
return process; | ||
} | ||
|
||
@Override | ||
public String toString() | ||
{ | ||
// hide non-freestanding weak forms and remove parens from freestanding ones | ||
String temp = process; | ||
if(temp.startsWith("(")) | ||
{ | ||
temp = temp.replaceFirst("[(]", ""); | ||
temp = temp.replaceFirst("[)]", ""); | ||
} | ||
temp = temp.replaceAll("[(].*?[)]", ""); | ||
return word + "―" + temp; | ||
} | ||
} |
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
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
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
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,54 @@ | ||
package language.deconjugator; | ||
|
||
import language.dictionary.DefTag; | ||
import java.util.HashSet; | ||
|
||
/** | ||
* Original (legacy) deconjugation rule. | ||
* Created by Laurens on 2/18/2017. | ||
*/ | ||
public class StdRuleOld implements DeconRule | ||
{ | ||
private String ending, replace, change; | ||
private DefTag neededTag, impliedTag; | ||
public StdRuleOld(String ending, String replace, String change, DefTag neededTag) | ||
{ | ||
this(ending, replace, change, neededTag, null); | ||
} | ||
public StdRuleOld(String ending, String replace, String change, DefTag neededTag, DefTag impliedTag) | ||
{ | ||
this.ending = ending; | ||
this.replace = replace; | ||
this.change = change; | ||
this.neededTag = neededTag; | ||
this.impliedTag = impliedTag; | ||
} | ||
public StdRuleOld(String ending, String replace, String change) | ||
{ | ||
this(ending, replace, change, null); | ||
} | ||
|
||
@Override | ||
public AbstractWord process(AbstractWord abstractword) | ||
{ | ||
ValidWordOld word = (ValidWordOld)abstractword; | ||
|
||
if(word.getProcess().contains(change)) | ||
{ | ||
return null;//don't stack the same conjugation onto itself | ||
} | ||
//ending matches: | ||
if(word.getWord().endsWith(ending)) | ||
{ | ||
//add tag and return | ||
HashSet<DefTag> tags = new HashSet<DefTag>(word.getNeededTags()); | ||
HashSet<DefTag> impliedTags = new HashSet<DefTag>(word.getImpliedTags()); | ||
if(neededTag != null)tags.add(neededTag); | ||
if(impliedTag != null)impliedTags.add(impliedTag); | ||
String newProcess = word.getProcess() + " " + change; | ||
return new ValidWordOld(word.getWord().substring(0, word.getWord().length() - ending.length()) + replace, tags, impliedTags, newProcess); | ||
} | ||
//doesn't match, don't add new word | ||
return null; | ||
} | ||
} |
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
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,64 @@ | ||
/* | ||
* Copyright (C) 2017 Laurens Weyn | ||
* | ||
* This program 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. | ||
* | ||
* This program 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. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package language.deconjugator; | ||
|
||
import language.dictionary.DefTag; | ||
import language.dictionary.Definition; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
/** | ||
* Holds a possible valid conjugation if a word exists with the valid tags | ||
* @author Laurens Weyn | ||
*/ | ||
public class ValidWordOld extends AbstractWord | ||
{ | ||
private Set<DefTag> impliedTags; | ||
|
||
public ValidWordOld(String word, Set<DefTag> neededTags, Set<DefTag> impliedTags, String process) | ||
{ | ||
super(word, word, neededTags, process); | ||
this.impliedTags = impliedTags; | ||
} | ||
public ValidWordOld(String word, String process) | ||
{ | ||
super(word, process); | ||
this.impliedTags = new HashSet<>(); | ||
} | ||
|
||
public Set<DefTag> getImpliedTags() | ||
{ | ||
return impliedTags; | ||
} | ||
|
||
public boolean defMatches(Definition def) | ||
{ | ||
if(def.getTags() == null && getNeededTags().isEmpty())return true;//still accept if no tags needed | ||
else if (def.getTags() == null)return false;//does not have needed tags | ||
|
||
for(DefTag needed:getNeededTags()) | ||
{ | ||
if(!def.getTags().contains(needed) &&!getImpliedTags().contains(needed)) | ||
{ | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
} |
Oops, something went wrong.