1 // Copyright 2012 Google Inc. All Rights Reserved.
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 package com.hughes.android.dictionary.parser.wiktionary;
17 import com.hughes.android.dictionary.parser.WikiTokenizer;
18 import com.hughes.android.dictionary.parser.wiktionary.AbstractWiktionaryParser.AppendAndIndexWikiCallback;
19 import com.hughes.android.dictionary.parser.wiktionary.AbstractWiktionaryParser.NameAndArgs;
21 import java.util.List;
24 class ItFunctionCallbacks {
26 static <T extends AbstractWiktionaryParser> void addGenericCallbacks(Map<String, FunctionCallback<T>> callbacks) {
27 callbacks.put("-hyph-", new Redispatch<T>("\n==== Sillabazione ====\n"));
28 callbacks.put("-pron-", new Redispatch<T>("\n==== Pronuncia ====\n"));
29 callbacks.put("-etim-", new Redispatch<T>("\n==== Etimologia / Derivazione ====\n"));
30 callbacks.put("-syn-", new Redispatch<T>("\n==== Sinonimi ====\n"));
31 callbacks.put("-ant-", new Redispatch<T>("\n==== Antonimi/Contrari ====\n"));
32 callbacks.put("-drv-", new Redispatch<T>("\n==== Parole derivate ====\n"));
33 callbacks.put("-prov-", new Redispatch<T>("\n==== Proverbi e modi di dire ====\n"));
34 callbacks.put("-rel-", new Redispatch<T>("\n==== Termini correlati ====\n"));
35 callbacks.put("-ref-", new Redispatch<T>("\n==== Note / Riferimenti ====\n"));
37 callbacks.put("-trans1-", new SkipSection<T>());
38 callbacks.put("-trans2-", new SkipSection<T>());
43 static final NameAndArgs<EnParser> NAME_AND_ARGS = new NameAndArgs<EnParser>();
46 static final class Redispatch<T extends AbstractWiktionaryParser> implements FunctionCallback<T> {
48 public Redispatch(String newText) {
49 this.newText = newText;
53 public boolean onWikiFunction(final WikiTokenizer wikiTokenizer, final String name, final List<String> args,
54 final Map<String, String> namedArgs,
56 final AppendAndIndexWikiCallback<T> appendAndIndexWikiCallback) {
57 if (!namedArgs.isEmpty() || args.size() != 0) {
60 appendAndIndexWikiCallback.dispatch(newText, null);
66 static final class SkipSection<T extends AbstractWiktionaryParser> implements FunctionCallback<T> {
67 public SkipSection() {
71 public boolean onWikiFunction(final WikiTokenizer wikiTokenizer, final String name, final List<String> args,
72 final Map<String, String> namedArgs,
74 final AppendAndIndexWikiCallback<T> appendAndIndexWikiCallback) {
75 while (wikiTokenizer.nextToken() != null) {
76 if (wikiTokenizer.isFunction() && wikiTokenizer.functionName().startsWith("-") && wikiTokenizer.functionName().endsWith("-")) {
77 wikiTokenizer.returnToLineStart();