fix #878 mapping output is a single line
This commit is contained in:
parent
ff351756ae
commit
47df8a9baa
4 changed files with 23 additions and 12 deletions
|
@ -121,17 +121,17 @@ public class KuromojiFile extends DictionaryFile<KuromojiItem> {
|
|||
String line = null;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
// Remove comments
|
||||
line = line.replaceAll("#.*$", StringUtil.EMPTY);
|
||||
final String replacedLine = line.replaceAll("#.*$", StringUtil.EMPTY).trim();
|
||||
|
||||
// Skip empty lines or comment lines
|
||||
if (line.trim().length() == 0) {
|
||||
if (replacedLine.length() == 0) {
|
||||
if (updater != null) {
|
||||
updater.write(line);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
final String[] values = KuromojiCSVUtil.parse(line);
|
||||
final String[] values = KuromojiCSVUtil.parse(replacedLine);
|
||||
String token = null;
|
||||
String segmentation = null;
|
||||
String reading = null;
|
||||
|
|
|
@ -39,8 +39,12 @@ import org.codelibs.fess.Constants;
|
|||
import org.codelibs.fess.dict.DictionaryException;
|
||||
import org.codelibs.fess.dict.DictionaryFile;
|
||||
import org.dbflute.optional.OptionalEntity;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class CharMappingFile extends DictionaryFile<CharMappingItem> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(CharMappingFile.class);
|
||||
|
||||
private static final String MAPPING = "mapping";
|
||||
|
||||
List<CharMappingItem> mappingItemList;
|
||||
|
@ -124,10 +128,10 @@ public class CharMappingFile extends DictionaryFile<CharMappingItem> {
|
|||
String line = null;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
// Remove comments
|
||||
line = line.replaceAll("#.*$", StringUtil.EMPTY);
|
||||
final String replacedLine = line.replaceAll("#.*$", StringUtil.EMPTY).trim();
|
||||
|
||||
// Skip empty lines or comment lines
|
||||
if (line.trim().length() == 0) {
|
||||
if (replacedLine.length() == 0) {
|
||||
if (updater != null) {
|
||||
updater.write(line);
|
||||
}
|
||||
|
@ -137,17 +141,25 @@ public class CharMappingFile extends DictionaryFile<CharMappingItem> {
|
|||
String[] inputs;
|
||||
String output;
|
||||
|
||||
final Matcher m = parsePattern.matcher(line.trim());
|
||||
final Matcher m = parsePattern.matcher(replacedLine);
|
||||
|
||||
if (!m.find()) {
|
||||
throw new DictionaryException("Failed to parse " + path);
|
||||
logger.warn("Failed to parse " + line + " in " + path);
|
||||
if (updater != null) {
|
||||
updater.write("# " + line);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
inputs = m.group(1).trim().split(",");
|
||||
output = m.group(2).trim();
|
||||
|
||||
if (inputs == null || output == null || inputs.length == 0) {
|
||||
throw new DictionaryException("Failed to parse " + path);
|
||||
logger.warn("Failed to parse " + line + " in " + path);
|
||||
if (updater != null) {
|
||||
updater.write("# " + line);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
id++;
|
||||
|
|
|
@ -33,7 +33,7 @@ public class CharMappingItem extends DictionaryItem {
|
|||
public CharMappingItem(final long id, final String[] inputs, final String output) {
|
||||
this.id = id;
|
||||
this.inputs = inputs;
|
||||
this.output = output;
|
||||
this.output = output == null ? null : output.replace("\n", " ");
|
||||
Arrays.sort(inputs);
|
||||
|
||||
if (id == 0) {
|
||||
|
@ -56,7 +56,7 @@ public class CharMappingItem extends DictionaryItem {
|
|||
}
|
||||
|
||||
public void setNewOutput(final String newOutput) {
|
||||
this.newOutput = newOutput;
|
||||
this.newOutput = newOutput == null ? null : newOutput.replace("\n", " ");
|
||||
}
|
||||
|
||||
public String[] getInputs() {
|
||||
|
|
|
@ -105,8 +105,7 @@
|
|||
key="labels.dict_mapping_target" /></label>
|
||||
<div class="col-sm-9">
|
||||
<la:errors property="output" />
|
||||
<la:textarea property="output" rows="5"
|
||||
styleClass="form-control" />
|
||||
<la:text property="output" styleClass="form-control" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Add table
Reference in a new issue