]> gitweb.fperrin.net Git - DictionaryPC.git/blob - src/com/hughes/android/dictionary/parser/wiktionary/FrFunctionCallbacks.java
Minor automated code simplifications.
[DictionaryPC.git] / src / com / hughes / android / dictionary / parser / wiktionary / FrFunctionCallbacks.java
1 // Copyright 2012 Google Inc. All Rights Reserved.
2 //
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
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
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.
14
15 package com.hughes.android.dictionary.parser.wiktionary;
16
17 import java.util.List;
18 import java.util.Map;
19
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;
23 import com.hughes.android.dictionary.parser.wiktionary.ItFunctionCallbacks.Redispatch;
24
25 class FrFunctionCallbacks {
26
27     static <T extends AbstractWiktionaryParser> void addGenericCallbacks(Map<String, FunctionCallback<T>> callbacks) {
28         callbacks.put("-étym-", new Redispatch<>("\n==== Étymologie ====\n"));
29         callbacks.put("-pron-", new Redispatch<>("\n==== Prononciation ====\n"));
30         callbacks.put("-voir-", new Redispatch<>("\n==== Voir aussi ====\n"));
31         callbacks.put("-drv-", new Redispatch<>("\n==== Dérivés ====\n"));
32         callbacks.put("-syn-", new Redispatch<>("\n==== Synonymes ====\n"));
33
34         callbacks.put("-apr-", new Redispatch<>("\n==== Apparentés étymologiques ====\n"));
35         callbacks.put("-hyper-", new Redispatch<>("\n==== Hyperonymes ====\n"));
36         callbacks.put("-hypo-", new Redispatch<>("\n==== Hyponymes ====\n"));
37         callbacks.put("-réf-", new Redispatch<>("\n==== Références ====\n"));
38         callbacks.put("-homo-", new Redispatch<>("\n==== Homophones ====\n"));
39         callbacks.put("-anagr-", new Redispatch<>("\n==== Anagrammes ====\n"));
40         callbacks.put("-voc-", new Redispatch<>("\n==== Vocabulaire apparenté par le sens ====\n"));
41         callbacks.put("-exp-", new Redispatch<>("\n==== Expressions ====\n"));
42         callbacks.put("-note-", new Redispatch<>("\n==== Note ====\n"));
43
44         callbacks.put("-trad-", new ItFunctionCallbacks.SkipSection<>());
45     }
46
47
48     static final NameAndArgs<EnParser> NAME_AND_ARGS = new NameAndArgs<>();
49
50
51     static final class MakeHeadingFromName<T extends AbstractWiktionaryParser> implements FunctionCallback<T> {
52         final String header;
53         public MakeHeadingFromName(String header) {
54             this.header = header;
55         }
56
57         @Override
58         public boolean onWikiFunction(final WikiTokenizer wikiTokenizer, final String name, final List<String> args,
59                                       final Map<String, String> namedArgs,
60                                       final T parser,
61                                       final AppendAndIndexWikiCallback<T> appendAndIndexWikiCallback) {
62             if (!namedArgs.isEmpty() || args.size() != 0) {
63                 return false;
64             }
65             //appendAndIndexWikiCallback.builder.append(String.format("<%s>", header));
66             appendAndIndexWikiCallback.dispatch("\n" + header + name + header, null);
67             //appendAndIndexWikiCallback.builder.append(String.format("</%s>\n", header));
68             return true;
69         }
70     }
71
72
73 }