本文整理汇总了Java中gate.util.InvalidOffsetException类的典型用法代码示例。如果您正苦于以下问题:Java InvalidOffsetException类的具体用法?Java InvalidOffsetException怎么用?Java InvalidOffsetException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
InvalidOffsetException类属于gate.util包,在下文中一共展示了InvalidOffsetException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: edit
import gate.util.InvalidOffsetException; //导入依赖的package包/类
/** Propagate edit changes to the document content and annotations. */
@Override
public void edit(Long start, Long end, DocumentContent replacement)
throws InvalidOffsetException {
if(!isValidOffsetRange(start, end)) throw new InvalidOffsetException("Offsets: "+start+"/"+end);
if(content != null)
((DocumentContentImpl)content).edit(start, end, replacement);
if(defaultAnnots != null)
((AnnotationSetImpl)defaultAnnots).edit(start, end, replacement);
if(namedAnnotSets != null) {
Iterator<AnnotationSet> iter = namedAnnotSets.values().iterator();
while(iter.hasNext())
((AnnotationSetImpl)iter.next()).edit(start, end, replacement);
}
// let the listeners know
fireContentEdited(new DocumentEvent(this, DocumentEvent.CONTENT_EDITED,
start, end));
}
示例2: actionPerformed
import gate.util.InvalidOffsetException; //导入依赖的package包/类
@Override
public void actionPerformed(ActionEvent evt) {
int increment = 1;
if((evt.getModifiers() & ActionEvent.SHIFT_MASK) > 0) {
// CTRL pressed -> use tokens for advancing
increment = SHIFT_INCREMENT;
if((evt.getModifiers() & ActionEvent.CTRL_MASK) > 0) {
increment = CTRL_SHIFT_INCREMENT;
}
}
long newValue = ann.getStartNode().getOffset().longValue() - increment;
if(newValue < 0) newValue = 0;
try {
moveAnnotation(set, ann, new Long(newValue), ann.getEndNode()
.getOffset());
} catch(InvalidOffsetException ioe) {
throw new GateRuntimeException(ioe);
}
}
示例3: addAll
import gate.util.InvalidOffsetException; //导入依赖的package包/类
/**
* Adds multiple annotations to this set in one go. All the objects in the
* provided collection should be of {@link gate.Annotation} type, otherwise a
* ClassCastException will be thrown. The provided annotations will be used to
* create new annotations using the appropriate add() methods from this set.
* The new annotations will have different IDs from the old ones (which is
* required in order to preserve the uniqueness of IDs inside an annotation
* set).
*
* @param c
* a collection of annotations
* @return <tt>true</tt> if the set has been modified as a result of this
* call.
*/
@Override
public boolean addAll(Collection<? extends Annotation> c) {
Iterator<? extends Annotation> annIter = c.iterator();
boolean changed = false;
while(annIter.hasNext()) {
Annotation a = annIter.next();
try {
add(a.getStartNode().getOffset(), a.getEndNode().getOffset(), a
.getType(), a.getFeatures());
changed = true;
} catch(InvalidOffsetException ioe) {
throw new IllegalArgumentException(ioe.toString());
}
}
return changed;
}
示例4: insertUpdate
import gate.util.InvalidOffsetException; //导入依赖的package包/类
@Override
public void insertUpdate(final javax.swing.event.DocumentEvent e) {
// propagate the edit to the document
try {
// deactivate our own listener so we don't get cycles
document.removeDocumentListener(gateDocListener);
document.edit(
new Long(e.getOffset()),
new Long(e.getOffset()),
new DocumentContentImpl(e.getDocument().getText(e.getOffset(),
e.getLength())));
} catch(BadLocationException ble) {
ble.printStackTrace(Err.getPrintWriter());
} catch(InvalidOffsetException ioe) {
ioe.printStackTrace(Err.getPrintWriter());
} finally {
// reactivate our listener
document.addDocumentListener(gateDocListener);
}
// //update the offsets in the list
// Component listView = annotationListView.getGUI();
// if(listView != null) listView.repaint();
}
示例5: removeUpdate
import gate.util.InvalidOffsetException; //导入依赖的package包/类
@Override
public void removeUpdate(final javax.swing.event.DocumentEvent e) {
// propagate the edit to the document
try {
// deactivate our own listener so we don't get cycles
// gateDocListener.setActive(false);
document.removeDocumentListener(gateDocListener);
document.edit(new Long(e.getOffset()),
new Long(e.getOffset() + e.getLength()),
new DocumentContentImpl(""));
} catch(InvalidOffsetException ioe) {
ioe.printStackTrace(Err.getPrintWriter());
} finally {
// reactivate our listener
// gateDocListener.setActive(true);
document.addDocumentListener(gateDocListener);
}
// //update the offsets in the list
// Component listView = annotationListView.getGUI();
// if(listView != null) listView.repaint();
}
示例6: getAt
import gate.util.InvalidOffsetException; //导入依赖的package包/类
/**
* Sub-range access for document content. Allows
* <code>documentContent[15..20]</code>. This works with ranges
* whose end points are any numeric type, so as well as using integer
* literals you can do <code>documentContent[ann.start()..ann.end()]</code>
* (as start and end return Long).
* @param self
* @param range
* @return
*/
public static DocumentContent getAt(DocumentContent self, Range<?> range) {
if(range.getFrom() instanceof Number) {
try {
return self.getContent(
Long.valueOf(((Number)range.getFrom()).longValue()),
Long.valueOf(((Number)range.getTo()).longValue()));
}
catch(InvalidOffsetException ioe) {
throw new IndexOutOfBoundsException(ioe.getMessage());
}
}
else {
throw new IllegalArgumentException(
"DocumentContent.getAt expects a numeric range");
}
}
示例7: extractEntityCandidates
import gate.util.InvalidOffsetException; //导入依赖的package包/类
public ArrayList<Entity> extractEntityCandidates(String query, String lang, String entity_type) throws ResourceInstantiationException, ExecutionException, InvalidOffsetException{
ArrayList<Entity> candidates = null;
switch (lang) {
case "en":
candidates = extractEntityCandidatesEN(query, lang, entity_type);
break;
case "de":
candidates = extractEntityCandidatesDE(query, lang, entity_type);
break;
case "nl":
candidates = extractEntityCandidatesNL(query, lang, entity_type);
break;
}
return candidates;
}
示例8: addNewAnnotation
import gate.util.InvalidOffsetException; //导入依赖的package包/类
protected void addNewAnnotation(Annotation ann, Iterator<Lookup> lookups,
AnnotationSet inputAS, AnnotationSet outputAS) {
int from = ann.getStartNode().getOffset().intValue();
int to = ann.getEndNode().getOffset().intValue();
//System.out.println("Trying to add annotation from "+from+" to "+to+" lookups="+lookups+"Annotation is "+ann);
while(lookups.hasNext()) {
Lookup lookup = lookups.next();
String type = gazStore.getLookupType(lookup);
type = getAnnotationTypeName(type);
FeatureMap fm = Factory.newFeatureMap();
gazStore.addLookupListFeatures(fm, lookup);
gazStore.addLookupEntryFeatures(fm, lookup);
try {
outputAS.add(new Long(from), new Long(to), type, fm);
} catch (InvalidOffsetException ex) {
throw new GateRuntimeException("Invalid offset exception - doclen/from/to="
+ document.getContent().size() + "/" + from + "/" + to + " / ", ex);
}
}
}
示例9: createCorpusFromURLs
import gate.util.InvalidOffsetException; //导入依赖的package包/类
/**
*
* @param lstSources list with URL sources
* @return Corpus with documents loaded from the URL list
* @throws MalformedURLException
* @throws ResourceInstantiationException
*/
@SuppressWarnings("unchecked")
public static Corpus createCorpusFromURLs(List<String> lstURL, int iBegin, int iEnd) throws MalformedURLException, ResourceInstantiationException, InvalidOffsetException
{
// create a corpus with the above documents
Corpus result = Factory.newCorpus("test corpus");
List<String> lstURLAux = lstURL.subList(iBegin, iEnd);
for(String sURL: lstURLAux)
{
//System.out.println("Load document from " + sURL);
Document doc = Factory.newDocument(new URL(sURL));
doc.setPreserveOriginalContent(false);
//sisob.GateToyParser.ParsersSemantic.Parser.prepareDocumentForAnnieExtraction(doc);
result.add(doc);
}
return result;
}
示例10: createCSVFileWithTypeOfClass
import gate.util.InvalidOffsetException; //导入依赖的package包/类
/**
* Create CSV from list of cInfoBlocks with some fields extracted
* @param sFileName Name of file with extension
* @param lstInfoBlocks List of researches
*/
public static BufferedWriter createCSVFileWithTypeOfClass(String sFileName, Class cTypeOfClass) throws IOException, InvalidOffsetException
{
File fField = new File(sFileName);
FileOutputStream fileOS = new java.io.FileOutputStream(fField, false);
OutputStreamWriter writer = new java.io.OutputStreamWriter(fileOS,"UTF-16");
BufferedWriter bw = new java.io.BufferedWriter(writer);
Field af[] = cTypeOfClass.getFields();
String sOut = "";
for(Field f : af)
{
String sAux = f.getName();
if(!sAux.startsWith("_"))
{
sOut += "\"" + sAux + "\";";
}
}
sOut += "\r\n";
bw.write(sOut);
return bw;
}
示例11: getAt
import gate.util.InvalidOffsetException; //导入依赖的package包/类
/**
* Sub-range access for document content. Allows
* <code>documentContent[15..20]</code>. This works with ranges
* whose end points are any numeric type, so as well as using integer
* literals you can do <code>documentContent[ann.start()..ann.end()]</code>
* (as start and end return Long).
* @param self
* @param range
* @return
*/
public static DocumentContent getAt(DocumentContent self, Range range) {
if(range.getFrom() instanceof Number) {
try {
return self.getContent(
Long.valueOf(((Number)range.getFrom()).longValue()),
Long.valueOf(((Number)range.getTo()).longValue()));
}
catch(InvalidOffsetException ioe) {
throw new IndexOutOfBoundsException(ioe.getMessage());
}
}
else {
throw new IllegalArgumentException(
"DocumentContent.getAt expects a numeric range");
}
}
示例12: buildObject
import gate.util.InvalidOffsetException; //导入依赖的package包/类
/**
* Create a GATE annotation in the given annotation set and return its ID.
*/
public Object buildObject(CAS cas, Document doc, AnnotationSet annSet,
Annotation currentAnn, FeatureStructure currentFS)
throws MappingException {
//if(!(currentFS instanceof AnnotationFS)) {
// throw new MappingException("GATE annotations can only be created from "
// + "UIMA annotations, and not from arbitrary feature structures.");
//}
//AnnotationFS uimaAnnot = (AnnotationFS)currentFS;
FeatureMap annotFeatures = Factory.newFeatureMap();
applyFeatureDefs(annotFeatures, cas, doc, annSet, currentAnn, currentFS);
int annotStart = currentFS.getIntValue(uimaAnnotationBeginFeature);
int annotEnd = currentFS.getIntValue(uimaAnnotationEndFeature);
// add returns the Integer ID
try {
return annSet.add(new Long(annotStart), new Long(annotEnd),
annotationType, annotFeatures);
}
catch(InvalidOffsetException ioe) {
throw new MappingException("Unexpected error creating annotation", ioe);
}
}
示例13: getText
import gate.util.InvalidOffsetException; //导入依赖的package包/类
/**
* Retrieves the underlying text for the given annotation in the
* document with given document id.
*
* @param annot
* @param documentId
* @return
*/
public String getText(Annotation annot, String documentId) {
try {
if(documentId.equals(srcDocumentID)) {
return srcSequence.getText(annot);
}
else if(documentId.equals(tgtDocumentID)) {
return tgtSequence.getText(annot);
}
}
catch(InvalidOffsetException ioe) {
throw new GateRuntimeException(ioe);
}
return null;
}
示例14: processEntityOccurance
import gate.util.InvalidOffsetException; //导入依赖的package包/类
public void processEntityOccurance(int start, int end, String instURI, String classURI) {
FeatureMap fm = Factory.newFeatureMap();
if (instURI != null) {
fm.put(FeatureConstants.INSTANCE, instURI);
}
fm.put(FeatureConstants.CLASS, classURI);
try {
annotationSet.add(Long.valueOf(start), Long.valueOf(end),
KIMConstants.LOOKUP, fm);
}
catch (InvalidOffsetException ioe) {
throw new LuckyException(ioe.toString());
}
++annotatedEntities;
if (!kimParser.isInterrupted() && annotationLimit > 0
&& annotatedEntities > annotationLimit) {
log.warn("More than " + annotationLimit +
" lookups found. Interrupting ...");
kimParser.setInterrupted(true);
}
}
示例15: getNodes
import gate.util.InvalidOffsetException; //导入依赖的package包/类
/** Returns the nodes corresponding to the Longs. The Nodes are created if
* they don't exist.
**/
private final Node[] getNodes(Long start, Long end) throws InvalidOffsetException
{
// are the offsets valid?
if(!doc.isValidOffsetRange(start, end)) {
throw new InvalidOffsetException("Offsets [" + start + ":" + end +
"] not valid for this document of size " + doc.getContent().size());
}
// the set has to be indexed by position in order to add, as we need
// to find out if nodes need creating or if they exist already
if(nodesByOffset == null) {
indexByStartOffset();
}
// find existing nodes if appropriate nodes don't already exist,
// create them
Node startNode = nodesByOffset.get(start);
if(startNode == null)
startNode = new NodeImpl(doc.getNextNodeId(), start);
Node endNode = null;
if(start.equals(end)){
endNode = startNode;
return new Node[]{startNode,endNode};
}
endNode = nodesByOffset.get(end);
if(endNode == null)
endNode = new NodeImpl(doc.getNextNodeId(), end);
return new Node[]{startNode,endNode};
}