Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2011 Ubiquitous Knowledge Processing (UKP) Lab Technische Universit├Ąt Darmstadt Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. /
 
 package de.tudarmstadt.ukp.dkpro.core.io.bnc;
 
 import static org.apache.commons.lang.StringUtils.isNotBlank;
 
 
Reader for the British National Corpus (XML version).

Author(s):
Richard Eckart de Castilho
 
 		outputs = {
 			"de.tudarmstadt.ukp.dkpro.core.api.metadata.type.DocumentMetaData",
 		    "de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence",
 		    "de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token",
 		    "de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Lemma",
 		    "de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS" })
 public class BncReader
 	extends XmlReaderText
 {
(character) contains a significant punctuation mark as identified by the CLAWS tagger.
 
 	private static final String TAG_CHARACTER = "c";

(word) represents a grammatical (not necessarily orthographic) word.
 
 	private static final String TAG_WORD = "w";

(s-unit) contains a sentence-like division of a text.
 
 	private static final String TAG_SUNIT = "s";

contains a single spoken text, i.e. a transcription or collection of transcriptions from a single source.
 
 	private static final String TAG_STEXT = "stext";

contains a single written text.
 
 	private static final String TAG_WTEXT = "wtext";

contains the full title of a work of any kind.
 
 	private static final String TAG_TITLE = "title";

the root tag
 
 	private static final String TAG_BNC_DOC = "bncDoc";
 
 	private static final String ATTR_C5 = "c5";
 
 	private static final String ATTR_HEADWORD = "hw";

Location of the mapping file for part-of-speech tags to UIMA types.
 
	@ConfigurationParameter(name = , mandatory = false)
Use this part-of-speech tag set to use to resolve the tag set mapping instead of using the tag set defined as part of the model meta data.
	@ConfigurationParameter(name = , mandatory = false)
	protected String posTagset;
	public void initialize(UimaContext aContext)
	{
		super.initialize(aContext);
		.setDefault(."classpath:/de/tudarmstadt/ukp/dkpro/" +
				"core/api/lexmorph/tagset/${language}-${pos.tagset}-pos.map");
		.setDefault("pos.tagset""c5");
	}
	protected void initCas(CAS aCasResource aResourceString aQualifier)
	{
		super.initCas(aCasaResourceaQualifier);
	}
	protected Handler newSaxHandler()
	{
		return new BncHandler();
	}
	public class BncHandler
	{
		private String documentId = null;
		private boolean captureText = false;
		private int sentenceStart = -1;
		private int tokenStart = -1;
		private String c5Tag = null;
		private String headword = null;
		private boolean complete = false;
		public void startElement(String aUriString aLocalNameString aName,
				Attributes aAttributes)
		{
			if (.equals(aName)) {
				 = aAttributes.getValue("xml:id");
			}
			else if (.equals(aName)) {
				 = true;
			}
			else if (.equals(aName) || .equals(aName)) {
				 = true;
			}
			else if (.equals(aName)) {
			}
			else if (.equals(aName) || .equals(aName)) {
				 = aAttributes.getValue();
			}
		}
		public void endElement(String aUriString aLocalNameString aName)
		{
			if (.equals(aName)) {
				DocumentMetaData.get(getJCas()).setDocumentTitle(getBuffer().toString().trim());
				DocumentMetaData.get(getJCas()).setDocumentId();
				 = false;
			}
			else if (.equals(aName) || .equals(aName)) {
				 = false;
				 = true;
			}
			else if (.equals(aName)) {
			}
			else if (.equals(aName) || .equals(aName)) {
					Token token = new Token(getJCas(), getBuffer().length());
					trim(token);
					if ( != null) {
						POS pos = (POSgetJCas().getCas().createAnnotation(posTag,
								token.getBegin(), token.getEnd());
						token.setPos(pos);
					}
					if ( != null) {
						Lemma lemma = new Lemma(getJCas(), token.getBegin(), token.getEnd());
						lemma.addToIndexes();
						token.setLemma(lemma);
					}
					token.addToIndexes();
				}
				 = -1;
			}
		}
		public void characters(char[] aChint aStartint aLength)
		{
			if () {
				throw new SAXException("Extra content after stext is not permitted.");
			}
			if () {
				super.characters(aChaStartaLength);
			}
		}
		public void ignorableWhitespace(char[] aChint aStartint aLength)
		{
			if () {
				throw new SAXException("Extra content after stext is not permitted.");
			}
			if () {
				super.ignorableWhitespace(aChaStartaLength);
			}
		}
		private void trim(Annotation aAnnotation)
		{
			StringBuilder buffer = getBuffer();
			int s = aAnnotation.getBegin();
			int e = aAnnotation.getEnd();
			while (Character.isWhitespace(buffer.charAt(s))) {
				s++;
			}
			while ((e > s+1) && Character.isWhitespace(buffer.charAt(e-1))) {
				e--;
			}
			aAnnotation.setBegin(s);
			aAnnotation.setEnd(e);
		}
	}
New to GrepCode? Check out our FAQ X