package data; import java.io.Serializable; import java.util.Arrays; import java.util.HashSet; import java.util.List; import org.apache.commons.lang3.StringUtils; import data.Enums.Msd; import gui.ValidationUtil; public class Word implements Serializable { public static final char PAD_CHARACTER = '-'; private String word; private String lemma; private String msd; private List taxonomy; private final HashSet VOWELS = new HashSet<>(Arrays.asList('a', 'e', 'i', 'o', 'u')); /** * Possible values: *

*

*/ //private char besedna_vrsta; public Word(String word, String lemma, String msd) { this.lemma = lemma; this.msd = normalizeMsd(msd); // veliko zacetnico ohranimo samo za lastna imena if (!ValidationUtil.isEmpty(this.msd) && !(this.msd.charAt(0) == 'S' && this.msd.length() >= 2 && this.msd.charAt(1) == 'l')) { this.word = word.toLowerCase(); } else { this.word = word; } } //private char besedna_vrsta; public Word(String word, String lemma, String msd, List taxonomy) { this.lemma = lemma; this.msd = normalizeMsd(msd); this.taxonomy = taxonomy; // veliko zacetnico ohranimo samo za lastna imena if (!ValidationUtil.isEmpty(this.msd) && !(this.msd.charAt(0) == 'S' && this.msd.length() >= 2 && this.msd.charAt(1) == 'l')) { this.word = word.toLowerCase(); } else { this.word = word; } } public Word() { } /** * Appends a number of '-' to msds which are not properly sized. * E.g. nouns should have 5 attributes, yet the last one isn't always defined (Somei vs. Sometd) * * @param msdInput * * @return */ private String normalizeMsd(String msdInput) { if (ValidationUtil.isEmpty(msdInput)) { return ""; } else { return StringUtils.rightPad(msdInput, Msd.getMsdLengthForType(msdInput), PAD_CHARACTER); } } public Word(String word) { this.word = word; } public String getWord() { return word; } public String getCVVWord() { return covertToCvv(word); } public String getCVVLemma() { return covertToCvv(lemma); } private String covertToCvv(String s) { char[] StringCA = s.toCharArray(); for (int i = 0; i < StringCA.length; i++) { StringCA[i] = VOWELS.contains(StringCA[i]) ? 'V' : 'C'; } return new String(StringCA); } public void setWord(String word) { this.word = word; } public List getTaxonomy() { return taxonomy; } public String getLemma() { return lemma; } public void setLemma(String lemma) { this.lemma = lemma; } public String getMsd() { return msd; } public String toString() { StringBuilder sb = new StringBuilder(); sb.append("beseda:\t") .append(getWord()) .append("\n") .append("lema:\t") .append(getLemma()) .append("\n") .append("msd:\t") .append(getMsd()) .append("\n"); return sb.toString(); } public String getForCf(CalculateFor calculateFor, boolean cvv) { String returnValue = ""; if (cvv) { returnValue = calculateFor == CalculateFor.WORD ? getCVVWord() : getCVVLemma(); } else { returnValue = calculateFor == CalculateFor.WORD ? getWord() : getLemma(); } return returnValue; } }