📄 eafskeletonparser.java
字号:
} else if (stereotype.equals( Constraint.stereoTypes[Constraint.SYMBOLIC_SUBDIVISION])) { c = new SymbolicSubdivision(); } else if (stereotype.equals( Constraint.stereoTypes[Constraint.SYMBOLIC_ASSOCIATION])) { c = new SymbolicAssociation(); } } if (c != null) { lt.addConstraint(c); } lt.setControlledVocabularyName(ltr.getControlledVocabulary()); linguisticTypes.add(lt); } tiers = new ArrayList(tierMap.size()); HashMap parentHash = new HashMap(); Iterator tierIt = tierMap.values().iterator(); TierRecord rec; TierImpl tier; LinguisticType type; Locale loc; while (tierIt.hasNext()) { tier = null; type = null; rec = (TierRecord) tierIt.next(); tier = new TierImpl(null, rec.getName(), rec.getParticipant(), null, null); Iterator typeIter = linguisticTypes.iterator(); while (typeIter.hasNext()) { LinguisticType lt = (LinguisticType) typeIter.next(); if (lt.getLinguisticTypeName().equals(rec.getLinguisticType())) { type = lt; break; } } if (type == null) { // don't add the tier, something's wrong continue; } tier.setLinguisticType(type); if (rec.getDefaultLocale() == null) { // default, en tier.setDefaultLocale(new Locale("en", "", "")); } else { Iterator locIt = locales.iterator(); while (locIt.hasNext()) { loc = (Locale) locIt.next(); if (loc.getLanguage().equals(rec.getDefaultLocale())) { tier.setDefaultLocale(loc); break; } } } if (rec.getParentTier() != null) { parentHash.put(tier, rec.getParentTier()); } if (rec.getAnnotator() != null) { tier.setAnnotator(rec.getAnnotator()); } tiers.add(tier); } // all Tiers are created. Now set all parent tiers Iterator parentIter = parentHash.keySet().iterator(); while (parentIter.hasNext()) { TierImpl t = (TierImpl) parentIter.next(); String parent = (String) parentHash.get(t); Iterator secIt = tiers.iterator(); while (secIt.hasNext()) { TierImpl pt = (TierImpl) secIt.next(); if (pt.getName().equals(parent)) { t.setParentTier(pt); break; } } } } //####################### // Content handler //####################### class EAFSkeletonHandler implements ContentHandler { /* (non-Javadoc) * @see org.xml.sax.ContentHandler#endDocument() */ public void endDocument() throws SAXException { } /* (non-Javadoc) * @see org.xml.sax.ContentHandler#startDocument() */ public void startDocument() throws SAXException { } /** * ContentHandler method * * @param ch the characters * @param start start index * @param end end index * * @throws SAXException sax exception */ public void characters(char[] ch, int start, int end) throws SAXException { content += new String(ch, start, end); } /* (non-Javadoc) * @see org.xml.sax.ContentHandler#ignorableWhitespace(char[], int, int) */ public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException { } /* (non-Javadoc) * @see org.xml.sax.ContentHandler#endPrefixMapping(java.lang.String) */ public void endPrefixMapping(String prefix) throws SAXException { } /* (non-Javadoc) * @see org.xml.sax.ContentHandler#skippedEntity(java.lang.String) */ public void skippedEntity(String name) throws SAXException { } /* (non-Javadoc) * @see org.xml.sax.ContentHandler#setDocumentLocator(org.xml.sax.Locator) */ public void setDocumentLocator(Locator locator) { } /* (non-Javadoc) * @see org.xml.sax.ContentHandler#processingInstruction(java.lang.String, java.lang.String) */ public void processingInstruction(String target, String data) throws SAXException { } /* (non-Javadoc) * @see org.xml.sax.ContentHandler#startPrefixMapping(java.lang.String, java.lang.String) */ public void startPrefixMapping(String prefix, String uri) throws SAXException { } /* (non-Javadoc) * @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes) */ public void startElement(String nameSpaceURI, String name, String rawName, Attributes attributes) throws SAXException { content = ""; if (name.equals("TIER")) { currentTierId = attributes.getValue("TIER_ID"); // First check whether this tier already exists, prevent duplicates if (!tierMap.containsKey(currentTierId)) { // create a record TierRecord tr = new TierRecord(); tr.setName(currentTierId); tierMap.put(currentTierId, tr); tierOrder.add(currentTierId); tr.setParticipant(attributes.getValue("PARTICIPANT")); tr.setAnnotator(attributes.getValue("ANNOTATOR")); tr.setLinguisticType(attributes.getValue( "LINGUISTIC_TYPE_REF")); tr.setDefaultLocale(attributes.getValue("DEFAULT_LOCALE")); tr.setParentTier(attributes.getValue("PARENT_REF")); } } else if (name.equals("LINGUISTIC_TYPE")) { LingTypeRecord ltr = new LingTypeRecord(); ltr.setLingTypeId(attributes.getValue("LINGUISTIC_TYPE_ID")); String timeAlignable = "true"; if ((attributes.getValue("TIME_ALIGNABLE") != null) && (attributes.getValue("TIME_ALIGNABLE").equals("false"))) { timeAlignable = "false"; } ltr.setTimeAlignable(timeAlignable); String graphicReferences = "false"; if ((attributes.getValue("GRAPHIC_REFERENCES") != null) && (attributes.getValue("GRAPHIC_REFERENCES").equals("true"))) { graphicReferences = "true"; } ltr.setGraphicReferences(graphicReferences); String stereotype = attributes.getValue("CONSTRAINTS"); ltr.setStereoType(stereotype); ltr.setControlledVocabulary(attributes.getValue( "CONTROLLED_VOCABULARY_REF")); lingTypeRecords.add(ltr); } else if (name.equals("LOCALE")) { String langCode = attributes.getValue("LANGUAGE_CODE"); String countryCode = attributes.getValue("COUNTRY_CODE"); if (countryCode == null) { countryCode = ""; } String variant = attributes.getValue("VARIANT"); if (variant == null) { variant = ""; } Locale l = new Locale(langCode, countryCode, variant); locales.add(l); } else if (name.equals("CONTROLLED_VOCABULARY")) { currentCVId = attributes.getValue("CV_ID"); currentCV = new ControlledVocabulary(currentCVId); String desc = attributes.getValue("DESCRIPTION"); if (desc != null) { currentCV.setDescription(desc); } cvList.add(currentCV); } else if (name.equals("CV_ENTRY")) { currentEntryDesc = attributes.getValue("DESCRIPTION"); } } /* (non-Javadoc) * @see org.xml.sax.ContentHandler#endElement(java.lang.String, java.lang.String, java.lang.String) */ public void endElement(String nameSpaceURI, String name, String rawName) throws SAXException { if (name.equals("CV_ENTRY")) { currentCV.addEntry(new CVEntry(content, currentEntryDesc)); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -