Mercurial > hg > mpdl-group
comparison software/mpdl-services/mpiwg-mpdl-lt/src/de/mpg/mpiwg/berlin/mpdl/lt/morph/app/SimpleMorphContentHandler.java @ 19:4a3641ae14d2
Erstellung
author | Josef Willenborg <jwillenborg@mpiwg-berlin.mpg.de> |
---|---|
date | Wed, 09 Nov 2011 15:32:05 +0100 |
parents | |
children | e845310098ba |
comparison
equal
deleted
inserted
replaced
18:dc5e9fcb3fdc | 19:4a3641ae14d2 |
---|---|
1 package de.mpg.mpiwg.berlin.mpdl.lt.morph.app; | |
2 | |
3 import org.xml.sax.*; | |
4 | |
5 | |
6 public class SimpleMorphContentHandler implements ContentHandler { | |
7 private Element currentElement; | |
8 private Lemma lemma; | |
9 private Form form; | |
10 | |
11 public SimpleMorphContentHandler() { | |
12 } | |
13 | |
14 public Form getForm() { | |
15 return form; | |
16 } | |
17 | |
18 public Lemma getLemma() { | |
19 return lemma; | |
20 } | |
21 | |
22 public void startDocument() throws SAXException { | |
23 } | |
24 | |
25 public void endDocument() throws SAXException { | |
26 } | |
27 | |
28 public void characters(char[] c, int start, int length) throws SAXException { | |
29 if (currentElement != null) { | |
30 String elemName = currentElement.name; | |
31 if (form != null) { | |
32 char[] cCopy = new char[length]; | |
33 System.arraycopy(c, start, cCopy, 0, length); | |
34 String charactersStr = String.valueOf(cCopy); | |
35 if (elemName.equals("provider")) | |
36 form.setProvider(charactersStr); | |
37 else if (elemName.equals("language")) | |
38 form.setLanguage(charactersStr); | |
39 else if (elemName.equals("form-name")) | |
40 form.setFormName(charactersStr); | |
41 else if (elemName.equals("lemma-name")) | |
42 form.setLemmaName(charactersStr); | |
43 else if (elemName.equals("pos")) | |
44 form.setPos(charactersStr); | |
45 else if (elemName.equals("tense")) | |
46 form.setTense(charactersStr); | |
47 else if (elemName.equals("voice")) | |
48 form.setVoice(charactersStr); | |
49 else if (elemName.equals("casus")) | |
50 form.setCasus(charactersStr); | |
51 else if (elemName.equals("number")) | |
52 form.setNumber(charactersStr); | |
53 else if (elemName.equals("mood")) | |
54 form.setMood(charactersStr); | |
55 else if (elemName.equals("person")) | |
56 form.setPerson(charactersStr); | |
57 else if (elemName.equals("gender")) | |
58 form.setGender(charactersStr); | |
59 else if (elemName.equals("definite")) | |
60 form.setDefinite(charactersStr); | |
61 } else if (lemma != null) { | |
62 char[] cCopy = new char[length]; | |
63 System.arraycopy(c, start, cCopy, 0, length); | |
64 String charactersStr = String.valueOf(cCopy); | |
65 if (elemName.equals("provider")) | |
66 lemma.setProvider(charactersStr); | |
67 else if (elemName.equals("language")) | |
68 lemma.setLanguage(charactersStr); | |
69 else if (elemName.equals("lemma-name")) | |
70 lemma.setLemmaName(charactersStr); | |
71 } | |
72 } | |
73 } | |
74 | |
75 public void ignorableWhitespace(char[] c, int start, int length) throws SAXException { | |
76 } | |
77 | |
78 public void processingInstruction(String target, String data) throws SAXException { | |
79 } | |
80 | |
81 public void setDocumentLocator(org.xml.sax.Locator arg1) { | |
82 } | |
83 | |
84 public void endPrefixMapping(String prefix) throws SAXException { | |
85 } | |
86 | |
87 public void skippedEntity(String name) throws SAXException { | |
88 } | |
89 | |
90 public void endElement(String uri, String localName, String name) throws SAXException { | |
91 currentElement = null; | |
92 } | |
93 | |
94 public void startElement(String uri, String localName, String name, Attributes attrs) throws SAXException { | |
95 currentElement = new Element(name); | |
96 if (name.equals("form")) { | |
97 form = new Form(); | |
98 } else if (name.equals("lemma")) { | |
99 lemma = new Lemma(); | |
100 } | |
101 } | |
102 | |
103 public void startPrefixMapping(String prefix, String uri) throws SAXException { | |
104 } | |
105 | |
106 private class Element { | |
107 String name; | |
108 String value; | |
109 | |
110 Element(String name) { | |
111 this.name = name; | |
112 } | |
113 | |
114 Element(String name, String value) { | |
115 this.name = name; | |
116 this.value = value; | |
117 } | |
118 } | |
119 } |