diff -r 7d6d969b10cf -r 4ea0f81a5d08 software/mpdl-services/mpiwg-mpdl-lt-web/dist-remote/mpiwg-mpdl-lt-web.jar
Binary file software/mpdl-services/mpiwg-mpdl-lt-web/dist-remote/mpiwg-mpdl-lt-web.jar has changed
diff -r 7d6d969b10cf -r 4ea0f81a5d08 software/mpdl-services/mpiwg-mpdl-lt-web/dist-remote/mpiwg-mpdl-lt-web.war
Binary file software/mpdl-services/mpiwg-mpdl-lt-web/dist-remote/mpiwg-mpdl-lt-web.war has changed
diff -r 7d6d969b10cf -r 4ea0f81a5d08 software/mpdl-services/mpiwg-mpdl-lt-web/dist/mpiwg-mpdl-lt-web.jar
Binary file software/mpdl-services/mpiwg-mpdl-lt-web/dist/mpiwg-mpdl-lt-web.jar has changed
diff -r 7d6d969b10cf -r 4ea0f81a5d08 software/mpdl-services/mpiwg-mpdl-lt-web/dist/mpiwg-mpdl-lt-web.war
Binary file software/mpdl-services/mpiwg-mpdl-lt-web/dist/mpiwg-mpdl-lt-web.war has changed
diff -r 7d6d969b10cf -r 4ea0f81a5d08 software/mpdl-services/mpiwg-mpdl-lt-web/src/de/mpg/mpiwg/berlin/mpdl/servlets/lt/GetDictionaryEntries.java
--- a/software/mpdl-services/mpiwg-mpdl-lt-web/src/de/mpg/mpiwg/berlin/mpdl/servlets/lt/GetDictionaryEntries.java Wed Dec 14 12:48:43 2011 +0100
+++ b/software/mpdl-services/mpiwg-mpdl-lt-web/src/de/mpg/mpiwg/berlin/mpdl/servlets/lt/GetDictionaryEntries.java Wed Dec 14 12:49:06 2011 +0100
@@ -3,6 +3,7 @@
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
@@ -15,12 +16,14 @@
import org.apache.commons.lang3.StringEscapeUtils;
import de.mpg.mpiwg.berlin.mpdl.exception.ApplicationException;
+import de.mpg.mpiwg.berlin.mpdl.lt.dict.app.Lexica;
import de.mpg.mpiwg.berlin.mpdl.lt.dict.app.Lexicon;
import de.mpg.mpiwg.berlin.mpdl.lt.dict.app.LexiconEntry;
import de.mpg.mpiwg.berlin.mpdl.lt.dict.db.LexHandler;
import de.mpg.mpiwg.berlin.mpdl.lt.general.Language;
import de.mpg.mpiwg.berlin.mpdl.lt.morph.app.Form;
import de.mpg.mpiwg.berlin.mpdl.lt.morph.app.Lemma;
+import de.mpg.mpiwg.berlin.mpdl.lt.text.norm.Normalizer;
import de.mpg.mpiwg.berlin.mpdl.servlets.util.ServletUtil;
public class GetDictionaryEntries extends HttpServlet {
@@ -45,47 +48,75 @@
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
String query = request.getParameter("query");
+ String queryDisplay = request.getParameter("queryDisplay");
String language = request.getParameter("language");
String inputType = request.getParameter("inputType");
String outputFormat = request.getParameter("outputFormat");
- String outputType = request.getParameter("outputType");
+ String[] outputTypesArray = request.getParameterValues("outputType");
String dictionary = request.getParameter("dictionary");
String normalization = request.getParameter("normalization");
- String resultPage = request.getParameter("resultPage");
+ String normalizationType = request.getParameter("normalizationType");
+ String resultPageNumber = request.getParameter("resultPageNumber");
+ String resultPageSize = request.getParameter("resultPageSize");
if (query == null)
query = "a*";
+ boolean isRangeQuery = false;
+ if (query.endsWith("*"))
+ isRangeQuery = true;
+ if (queryDisplay == null)
+ queryDisplay = query;
if (language == null)
language = "eng";
if (inputType == null || ! (inputType.equals("form") || inputType.equals("lemma")))
inputType = "form";
- if (outputFormat == null || ! (outputFormat.equals("xml") || outputFormat.equals("html")))
+ if (outputFormat == null || ! (outputFormat.equals("xml") || outputFormat.equals("html") || outputFormat.equals("htmlFragment")))
outputFormat = "xml";
- if (outputType == null || ! (outputType.equals("compact") || outputType.equals("full")))
- outputType = "compact";
+ ArrayList outputTypes = new ArrayList();
+ if (outputTypesArray == null) {
+ outputTypes.add("allCompact");
+ } else if (isRangeQuery) {
+ outputTypes.add("dictCompact");
+ } else {
+ outputTypes = new ArrayList(Arrays.asList(outputTypesArray));
+ }
if (normalization == null || ! (normalization.equals("none") || normalization.equals("reg") || normalization.equals("reg norm")))
normalization = "norm";
+ if (normalizationType == null || ! (normalizationType.equals("display") || normalizationType.equals("dictionary")))
+ normalizationType = "dictionary";
String xmlDict = "all";
if (dictionary != null)
xmlDict = dictionary;
- int pn = 1;
- if (resultPage != null)
- pn = new Integer(resultPage);
- boolean isRangeQuery = false;
- if (query.endsWith("*"))
- isRangeQuery = true;
- String xmlQueryString = "" + query + "" + "" + language + "" + "" + inputType + "" +
- "" + outputFormat + "" + "" + outputType + "" + "" + xmlDict + "" +
- "" + normalization + "" + "";
+ int pageNumber = 1;
+ int pageSize = 50;
+ if (resultPageNumber != null)
+ pageNumber = new Integer(resultPageNumber);
+ if (resultPageSize != null)
+ pageSize = new Integer(resultPageSize);
+ String xmlQueryString = "";
+ xmlQueryString = xmlQueryString + "" + query + "";
+ xmlQueryString = xmlQueryString + "" + queryDisplay + "";
+ xmlQueryString = xmlQueryString + "" + language + "";
+ xmlQueryString = xmlQueryString + "" + inputType + "";
+ xmlQueryString = xmlQueryString + "" + outputFormat + "";
+ xmlQueryString = xmlQueryString + "" + outputTypes + "";
+ xmlQueryString = xmlQueryString + "" + xmlDict + "";
+ xmlQueryString = xmlQueryString + "" + normalization + "";
+ xmlQueryString = xmlQueryString + "" + normalizationType + "";
+ if (isRangeQuery) {
+ xmlQueryString = xmlQueryString + "" + pageNumber + "";
+ xmlQueryString = xmlQueryString + "" + pageSize + "";
+ }
+ xmlQueryString = xmlQueryString + "";
try {
if (outputFormat.equals("xml"))
response.setContentType("text/xml");
- else if (outputFormat.equals("html"))
+ else if (outputFormat.equals("html") || outputFormat.equals("htmlFragment"))
response.setContentType("text/html");
else
response.setContentType("text/xml");
PrintWriter out = response.getWriter();
if (query == null || query.isEmpty()) {
- out.print("request parameter query is empty. Please specify a query.");
+ out.print("request parameter \"query\" is empty. Please specify a query.");
out.close();
return;
}
@@ -94,23 +125,34 @@
if (isRangeQuery) {
String queryTmp = query.substring(0, query.length() - 1); // without last star
if (dictionary != null)
- dictionaries = lexHandler.getLexEntriesByLexiconBeginningWith(dictionary, queryTmp, pn);
+ dictionaries = lexHandler.getLexEntriesByLexiconBeginningWith(dictionary, queryTmp, pageNumber, pageSize);
else
- dictionaries = lexHandler.getLexEntriesBeginningWith(language, queryTmp, pn);
+ dictionaries = lexHandler.getLexEntriesBeginningWith(language, queryTmp, pageNumber, pageSize);
} else {
- lemmas = lexHandler.getLemmas(query, inputType, language, normalization);
- dictionaries = lexHandler.getLexEntries(lemmas, language, dictionary);
+ String lang = language;
+ if (dictionary != null) {
+ Lexicon lexicon = Lexica.getInstance().getLexicon(dictionary);
+ if (lexicon != null)
+ lang = lexicon.getSourceLanguage();
+ }
+ int normMode = Normalizer.DICTIONARY;
+ if (normalization.equals("none"))
+ normMode = Normalizer.NONE;
+ else if (normalizationType.equals("display"))
+ normMode = Normalizer.DISPLAY;
+ lemmas = lexHandler.getLemmas(query, inputType, lang, normMode);
+ dictionaries = lexHandler.getLexEntries(lemmas, lang, dictionary, query);
}
String baseUrl = ServletUtil.getInstance().getBaseUrl(request);
Date end = new Date();
String elapsedTime = String.valueOf(end.getTime() - begin.getTime());
String result = "";
if (outputFormat == null || outputFormat.equals("xml"))
- result = createXmlOutputString(query, lemmas, dictionaries, outputType, baseUrl, xmlQueryString, elapsedTime);
- else if (outputFormat.equals("html"))
- result = createHtmlOutputString(query, lemmas, dictionaries, outputType, elapsedTime);
+ result = createXmlOutputString(query, lemmas, dictionaries, outputTypes, baseUrl, xmlQueryString, elapsedTime);
+ else if (outputFormat.equals("html") || outputFormat.equals("htmlFragment"))
+ result = createHtmlOutputString(query, queryDisplay, language, lemmas, dictionaries, pageNumber, pageSize, isRangeQuery, outputFormat, outputTypes, elapsedTime);
else
- result = createXmlOutputString(query, lemmas, dictionaries, outputType, baseUrl, xmlQueryString, elapsedTime);
+ result = createXmlOutputString(query, lemmas, dictionaries, outputTypes, baseUrl, xmlQueryString, elapsedTime);
out.print(result);
out.close();
} catch (ApplicationException e) {
@@ -122,12 +164,30 @@
}
- private String createXmlOutputString(String query, ArrayList lemmas, ArrayList lexicons, String outputType, String baseUrl, String xmlQueryString, String elapsedTime) {
+ private String createXmlOutputString(String query, ArrayList lemmas, ArrayList lexicons, ArrayList outputTypes, String baseUrl, String xmlQueryString, String elapsedTime) {
+ boolean outputTypeMorphCompact = false;
+ if (outputTypes.contains("allCompact") || outputTypes.contains("morphCompact"))
+ outputTypeMorphCompact = true;
+ boolean outputTypeMorphFull = false;
+ if (outputTypes.contains("allFull") || outputTypes.contains("morphFull"))
+ outputTypeMorphFull = true;
+ boolean outputTypeDictCompact = false;
+ if (outputTypes.contains("allCompact") || outputTypes.contains("dictCompact"))
+ outputTypeDictCompact = true;
+ boolean outputTypeDictFull = false;
+ if (outputTypes.contains("allFull") || outputTypes.contains("dictFull"))
+ outputTypeDictFull = true;
+ boolean outputTypeWikiCompact = false;
+ if (outputTypes.contains("allCompact") || outputTypes.contains("wikiCompact"))
+ outputTypeWikiCompact = true;
+ boolean outputTypeWikiFull = false;
+ if (outputTypes.contains("allFull") || outputTypes.contains("wikiFull"))
+ outputTypeWikiFull = true;
String result = "";
result = result + "" + "MPIWG MPDL language technology service (see: " + "" + baseUrl + "), Max Planck Institute for the History of Science, Berlin." + "";
result = result + xmlQueryString;
result = result + "" + elapsedTime + "";
- if (lemmas != null && ! lemmas.isEmpty()) {
+ if ((outputTypeMorphCompact || outputTypeMorphFull) && lemmas != null && ! lemmas.isEmpty()) {
result = result + "";
for (int i=0; i";
result = result + "" + lemmaName + "";
- if (outputType != null && outputType.equals("full")) {
+ if (outputTypeMorphFull) {
String lemmaProvider = lemma.getProvider();
result = result + "" + lemmaProvider + "";
result = result + "" + language + "";
@@ -147,7 +207,7 @@
String remoteUrl = "http://www.perseus.tufts.edu/hopper/morph?l=" + lemmaName + "&la=" + "greek";
result = result + "" + remoteUrl + "";
}
- if (outputType != null && outputType.equals("full")) {
+ if (outputTypeMorphFull) {
ArrayList";
}
- if (lexicons != null) {
+ if ((outputTypeDictCompact || outputTypeDictFull) && lexicons != null) {
result = result + "";
for (int i=0; i";
}
- if (outputType != null && outputType.equals("full") && lemmas != null && ! lemmas.isEmpty()) {
+ if ((outputTypeWikiCompact || outputTypeWikiFull) && lemmas != null && ! lemmas.isEmpty()) {
result = result + "";
+ String language = null;
for (int i=0; i";
result = result + "" + lemmaName + "";
String wikiHrefExact = "http://" + language + ".wikipedia.org/wiki/" + lemmaName;
@@ -191,65 +255,137 @@
result = result + "" + wikiHrefSearch + "";
result = result + "";
}
+ if (language != null && Language.getInstance().isGerman(language) && query != null) {
+ String[] queryFormNames = query.split(" ");
+ for (int j=0; j";
+ result = result + "" + queryFormName + "";
+ String wikiHrefExact = "http://" + language + ".wikipedia.org/wiki/" + queryFormName;
+ String wikiHrefSearch = "http://" + language + ".wikipedia.org/wiki/index.php?search=" + queryFormName;
+ result = result + "" + wikiHrefExact + "";
+ result = result + "" + wikiHrefSearch + "";
+ result = result + "";
+ }
+ }
result = result + "";
}
result = result + "";
return result;
}
- private String createHtmlOutputString(String query, ArrayList lemmas, ArrayList lexicons, String outputType, String elapsedTime) {
+ private String createHtmlOutputString(String query, String queryDisplay, String language, ArrayList lemmas, ArrayList lexicons, int pageNumber, int pageSize, boolean isRangeQuery, String outputFormat, ArrayList outputTypes, String elapsedTime) {
+ boolean outputTypeMorphCompact = false;
+ if (outputTypes.contains("allCompact") || outputTypes.contains("morphCompact"))
+ outputTypeMorphCompact = true;
+ boolean outputTypeMorphFull = false;
+ if (outputTypes.contains("allFull") || outputTypes.contains("morphFull"))
+ outputTypeMorphFull = true;
+ boolean outputTypeDictCompact = false;
+ if (outputTypes.contains("allCompact") || outputTypes.contains("dictCompact"))
+ outputTypeDictCompact = true;
+ boolean outputTypeDictFull = false;
+ if (outputTypes.contains("allFull") || outputTypes.contains("dictFull"))
+ outputTypeDictFull = true;
+ boolean outputTypeWikiCompact = false;
+ if (outputTypes.contains("allCompact") || outputTypes.contains("wikiCompact"))
+ outputTypeWikiCompact = true;
+ boolean outputTypeWikiFull = false;
+ if (outputTypes.contains("allFull") || outputTypes.contains("wikiFull"))
+ outputTypeWikiFull = true;
String result = "";
result = result + "";
result = result + "";
- result = result + "Word information for: \"" + query + "\"";
+ result = result + "WordInfo for: \"" + queryDisplay + "\"";
+ result = result + "";
+ result = result + getJavascriptFunctions();
result = result + "";
- result = result + "";
+ result = result + "";
result = result + "
";
result = result + "
[This is a MPIWG MPDL language technology service]
";
result = result + "
";
result = result + "";
- result = result + "
Word information for: \"" + query + "\"
";
- if (lemmas != null && ! lemmas.isEmpty()) {
- result = result + "
Morphology
";
+ result = result + "
WordInfo
";
+
+ result = result + "";
+ result = result + "";
+
+ if ((outputTypeMorphCompact || outputTypeMorphFull) && lemmas != null && ! lemmas.isEmpty()) {
+ result = result + "Morphology";
+ result = result + "";
result = result + "
";
- result = result + "";
+ result = result + "
" + "" + "Lemmata" + "";
+ result = result + "
";
for (int i=0; i";
- result = result + lemmaName;
- if (outputType != null && outputType.equals("full")) {
+ String providerText = "";
+ String externalLinkText = "";
+ String formsText = "";
+ if (outputTypeMorphFull) {
String lemmaProvider = lemma.getProvider();
- result = result + " (data provider: " + lemmaProvider + ")";
+ providerText = " (data provider: " + lemmaProvider + ")";
}
if (Language.getInstance().isArabic(language) || Language.getInstance().isLatin(language))
- result = result + " (external link: " + lemmaName + ")";
+ externalLinkText = " (external link: " + lemmaName + ")";
else if (Language.getInstance().isGreek(language))
- result = result + " (external link: " + lemmaName + ")";
- if (outputType != null && outputType.equals("full")) {
- ArrayList
";
+ if (outputTypeMorphFull) {
+ result = result + "
" + formsText + "
";
+ } else if (outputTypeMorphCompact) {
+ result = result + "
" + formsText + "
";
+ }
}
result = result + "
";
+ result = result + "
";
+ result = result + "";
+ result = result + "";
}
- if (lexicons != null && ! lexicons.isEmpty()) {
- result = result + "
Dictionary
";
+ if ((outputTypeDictCompact || outputTypeDictFull) && lexicons != null && ! lexicons.isEmpty()) {
+ if (isRangeQuery) {
+ int pageNumberUp = 1;
+ if (pageNumber > 1)
+ pageNumberUp = pageNumber - 1;
+ int pageNumberDown = pageNumber + 1;
+ int from = (pageNumber * pageSize) - pageSize + 1;
+ int to = pageNumber * pageSize;
+ result = result + "
";
+ result = result + "
";
+ result = result + "
Page:
";
+ result = result + "
";
+ result = result + "
" + pageNumber + "
";
+ result = result + "
";
+ result = result + "
(" + from + " - " + to + ")
";
+ result = result + "
";
+ result = result + "
";
+ }
+ result = result + "Dictionary";
+ result = result + "";
result = result + "
";
- result = result + "";
for (int i=0; i";
@@ -283,34 +419,50 @@
}
String formName = entry.getFormName();
String dictName = lexicon.getName();
- if (outputType != null && outputType.equals("full")) {
- result = result + "
" + "" + formName + "
" + entryContent + "
";
- } else if (outputType != null && outputType.equals("compact")) {
- result = result + "