001 // This file is part of AceWiki.
002 // Copyright 2008-2012, AceWiki developers.
003 //
004 // AceWiki is free software: you can redistribute it and/or modify it under the terms of the GNU
005 // Lesser General Public License as published by the Free Software Foundation, either version 3 of
006 // the License, or (at your option) any later version.
007 //
008 // AceWiki is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
009 // even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
010 // Lesser General Public License for more details.
011 //
012 // You should have received a copy of the GNU Lesser General Public License along with AceWiki. If
013 // not, see http://www.gnu.org/licenses/.
014
015 package ch.uzh.ifi.attempto.base;
016
017 import java.util.ArrayList;
018 import java.util.Arrays;
019 import java.util.List;
020
021 /**
022 * This class is the default implementation of a text operator.
023 *
024 * @author Tobias Kuhn
025 */
026 public class DefaultTextOperator implements TextOperator {
027
028 public TextElement createTextElement(String text) {
029 return new TextElement(text);
030 }
031
032 public String getTextInContext(TextElement textElement, String preceding, String following) {
033 return textElement.getOriginalText();
034 }
035
036 public List<String> splitIntoTokens(String text) {
037 for (char c : ".,:;?!".toCharArray()) {
038 text = text.replaceAll("\\" + c + "\\s", " " + c + " ");
039 text = text.replaceAll("\\" + c + "$", " " + c);
040 }
041 ArrayList<String> tokens = new ArrayList<String>(Arrays.asList(text.split(" ")));
042 while (tokens.contains("")) tokens.remove("");
043 return tokens;
044 }
045
046 public String getGlue(TextElement left, TextElement right) {
047 if (right.getText().matches("[.?!,;:]")) {
048 return "";
049 }
050 return " ";
051 }
052
053 }