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 java.util.List;
20 import com.hughes.android.dictionary.parser.WikiTokenizer;
21 import com.hughes.android.dictionary.parser.wiktionary.AbstractWiktionaryParser.AppendAndIndexWikiCallback;
22 import com.hughes.android.dictionary.parser.wiktionary.AbstractWiktionaryParser.NameAndArgs;
24 class ItFunctionCallbacks {
26 static <T extends AbstractWiktionaryParser> void addGenericCallbacks(
27 Map<String, FunctionCallback<T>> callbacks) {
28 callbacks.put("-hyph-", new Redispatch<T>("\n==== Sillabazione ====\n"));
29 callbacks.put("-pron-", new Redispatch<T>("\n==== Pronuncia ====\n"));
30 callbacks.put("-etim-", new Redispatch<T>("\n==== Etimologia / Derivazione ====\n"));
31 callbacks.put("-syn-", new Redispatch<T>("\n==== Sinonimi ====\n"));
32 callbacks.put("-ant-", new Redispatch<T>("\n==== Antonimi/Contrari ====\n"));
33 callbacks.put("-drv-", new Redispatch<T>("\n==== Parole derivate ====\n"));
34 callbacks.put("-prov-", new Redispatch<T>("\n==== Proverbi e modi di dire ====\n"));
35 callbacks.put("-ref-", new Redispatch<T>("\n==== Note / Riferimenti ====\n"));
36 callbacks.put("-rel-", new Redispatch<T>("\n==== Termini correlati ====\n"));
37 callbacks.put("-var-", new Redispatch<T>("\n==== Varianti ====\n"));
39 callbacks.put("-trans1-", new SkipSection<T>());
40 callbacks.put("-trans2-", new SkipSection<T>());
41 callbacks.put("-ref-", new SkipSection<T>());
44 static final NameAndArgs<EnParser> NAME_AND_ARGS = new NameAndArgs<EnParser>();
46 static final class Redispatch<T extends AbstractWiktionaryParser> implements
50 public Redispatch(String newText) {
51 this.newText = newText;
55 public boolean onWikiFunction(final WikiTokenizer wikiTokenizer, final String name,
56 final List<String> args,
57 final Map<String, String> namedArgs,
59 final AppendAndIndexWikiCallback<T> appendAndIndexWikiCallback) {
60 if (!namedArgs.isEmpty() || args.size() != 0) {
63 appendAndIndexWikiCallback.dispatch(newText, null);
68 static final class SkipSection<T extends AbstractWiktionaryParser> implements
70 public SkipSection() {
74 public boolean onWikiFunction(final WikiTokenizer wikiTokenizer, final String name,
75 final List<String> args,
76 final Map<String, String> namedArgs,
78 final AppendAndIndexWikiCallback<T> appendAndIndexWikiCallback) {
79 while (wikiTokenizer.nextToken() != null) {
80 if (wikiTokenizer.isFunction()
81 && wikiTokenizer.functionName().startsWith("-")
82 && wikiTokenizer.functionName().endsWith("-")
83 // Hack to prevent infinite-looping, would be better to check that this func was at the start of the line.
84 && !wikiTokenizer.functionName().contains("trans")) {
85 wikiTokenizer.returnToLineStart();