本文整理汇总了Java中gate.util.InvalidOffsetException类的典型用法代码示例。如果您正苦于以下问题:Java InvalidOffsetException类的具体用法?Java InvalidOffsetException怎么用?Java InvalidOffsetException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
InvalidOffsetException类属于gate.util包,在下文中一共展示了InvalidOffsetException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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));
}
开发者ID:GateNLP,项目名称:gate-core,代码行数:19,代码来源:DocumentImpl.java
示例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);
}
}
开发者ID:GateNLP,项目名称:gate-core,代码行数:20,代码来源:AnnotationEditor.java
示例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;
}
开发者ID:GateNLP,项目名称:gate-core,代码行数:31,代码来源:AnnotationSetImpl.java
示例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();
}
开发者ID:GateNLP,项目名称:gate-core,代码行数:24,代码来源:TextualDocumentView.java
示例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();
}
开发者ID:GateNLP,项目名称:gate-core,代码行数:22,代码来源:TextualDocumentView.java
示例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");
}
}
开发者ID:KHP-Informatics,项目名称:ADRApp,代码行数:27,代码来源:GateGroovyMethods.java
示例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;
}
开发者ID:entityclassifier-eu,项目名称:entityclassifier-core,代码行数:18,代码来源:THDInstance.java
示例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);
}
}
}
开发者ID:johann-petrak,项目名称:gateplugin-StringAnnotation,代码行数:21,代码来源:FeatureGazetteer.java
示例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;
}
开发者ID:eduardoguzman,项目名称:sisob-data-extractor,代码行数:29,代码来源:cUtils.java
示例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;
}
开发者ID:eduardoguzman,项目名称:sisob-data-extractor,代码行数:30,代码来源:cUtils.java
示例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");
}
}
开发者ID:Network-of-BioThings,项目名称:GettinCRAFTy,代码行数:27,代码来源:GateGroovyMethods.java
示例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);
}
}
开发者ID:Network-of-BioThings,项目名称:GettinCRAFTy,代码行数:29,代码来源:GateAnnotationBuilder.java
示例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;
}
开发者ID:Network-of-BioThings,项目名称:GettinCRAFTy,代码行数:25,代码来源:DefaultIteratingMethod.java
示例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);
}
}
开发者ID:Network-of-BioThings,项目名称:GettinCRAFTy,代码行数:25,代码来源:KimGazetteer.java
示例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};
}
开发者ID:GateNLP,项目名称:gate-core,代码行数:34,代码来源:AnnotationSetImpl.java
示例16: add
import gate.util.InvalidOffsetException; //导入依赖的package包/类
/** Create and add an annotation and return its id */
@Override
public Integer add(Long start, Long end, String type, FeatureMap features)
throws InvalidOffsetException {
Node[] nodes = getNodes(start,end);
// delegate to the method that adds annotations with existing nodes
return add(nodes[0], nodes[1], type, features);
}
开发者ID:GateNLP,项目名称:gate-core,代码行数:9,代码来源:AnnotationSetImpl.java
示例17: writeDocument
import gate.util.InvalidOffsetException; //导入依赖的package包/类
/**
* Write a GATE document to the specified JsonGenerator. The document
* text will be written as a property named "text" and the specified
* annotations will be written as "entities".
*
* @param doc the document to write
* @param annotationsMap annotations to write.
* @param json the {@link JsonGenerator} to write to.
* @throws JsonGenerationException if a problem occurs while
* generating the JSON
* @throws IOException if an I/O error occurs.
*/
public static void writeDocument(Document doc,
Map<String, Collection<Annotation>> annotationsMap, JsonGenerator json)
throws JsonGenerationException, IOException {
try {
writeDocument(doc, 0L, doc.getContent().size(), annotationsMap, json);
} catch(InvalidOffsetException e) {
// shouldn't happen
throw new GateRuntimeException(
"Got invalid offset exception when passing "
+ "offsets that are known to be valid");
}
}
开发者ID:GateNLP,项目名称:gate-core,代码行数:25,代码来源:DocumentJsonUtils.java
示例18: getContent
import gate.util.InvalidOffsetException; //导入依赖的package包/类
@Override
public DocumentContent getContent(Long start, Long end)
throws InvalidOffsetException
{
if(! isValidOffsetRange(start, end))
throw new InvalidOffsetException("Invalid offset range "+start+" to "+end+
" for document content of length "+this.size());
return new DocumentContentImpl(
content.substring(start.intValue(), end.intValue())
);
}
开发者ID:GateNLP,项目名称:gate-core,代码行数:13,代码来源:DocumentContentImpl.java
示例19: moveAnnotation
import gate.util.InvalidOffsetException; //导入依赖的package包/类
/**
* Changes the span of an existing annotation by creating a new annotation
* with the same ID, type and features but with the new start and end offsets.
*
* @param set
* the annotation set
* @param oldAnnotation
* the annotation to be moved
* @param newStartOffset
* the new start offset
* @param newEndOffset
* the new end offset
*/
protected void moveAnnotation(AnnotationSet set, Annotation oldAnnotation,
Long newStartOffset, Long newEndOffset) throws InvalidOffsetException {
// Moving is done by deleting the old annotation and creating a new one.
// If this was the last one of one type it would mess up the gui which
// "forgets" about this type and then it recreates it (with a different
// colour and not visible.
// In order to avoid this problem, we'll create a new temporary annotation.
Annotation tempAnn = null;
if(set.get(oldAnnotation.getType()).size() == 1) {
// create a clone of the annotation that will be deleted, to act as a
// placeholder
Integer tempAnnId =
set.add(oldAnnotation.getStartNode(), oldAnnotation.getStartNode(),
oldAnnotation.getType(), oldAnnotation.getFeatures());
tempAnn = set.get(tempAnnId);
}
Integer oldID = oldAnnotation.getId();
set.remove(oldAnnotation);
set.add(oldID, newStartOffset, newEndOffset, oldAnnotation.getType(),
oldAnnotation.getFeatures());
Annotation newAnn = set.get(oldID);
// update the selection to the new annotation
getOwner().selectAnnotation(new AnnotationDataImpl(set, newAnn));
editAnnotation(newAnn, set);
// remove the temporary annotation
if(tempAnn != null) set.remove(tempAnn);
owner.annotationChanged(newAnn, set, null);
}
开发者ID:GateNLP,项目名称:gate-core,代码行数:42,代码来源:AnnotationEditor.java
示例20: actionPerformed
import gate.util.InvalidOffsetException; //导入依赖的package包/类
@Override
public void actionPerformed(ActionEvent evt){
if(annotationEditor == null) return;
int start = textPane.getSelectionStart();
int end = textPane.getSelectionEnd();
if(start != end){
textPane.setSelectionStart(start);
textPane.setSelectionEnd(start);
//create a new annotation
//find the selected set
int row = mainTable.getSelectedRow();
//select the default annotation set if none selected
if(row < 0) row = 0;
//find the set handler
while(!(tableRows.get(row) instanceof SetHandler)) row --;
AnnotationSet set = ((SetHandler)tableRows.get(row)).set;
try{
Integer annId = set.add(new Long(start), new Long(end),
lastAnnotationType, Factory.newFeatureMap());
Annotation ann = set.get(annId);
//select the annotation set in the tree view and expand it
//to avoid the next annotation to be always in the default set
if (tableRows.get(row) instanceof SetHandler) {
((SetHandler)tableRows.get(row)).setExpanded(true);
mainTable.getSelectionModel().setSelectionInterval(row, row);
}
//make sure new annotation is visible
setTypeSelected(set.getName(), ann.getType(), true);
//edit the new annotation
pendingEvents.offer(new PerformActionEvent(
new EditAnnotationAction(new AnnotationDataImpl(set, ann))));
eventMinder.restart();
}catch(InvalidOffsetException ioe){
//this should never happen
throw new GateRuntimeException(ioe);
}
}
}
开发者ID:GateNLP,项目名称:gate-core,代码行数:39,代码来源:AnnotationSetsView.java
注:本文中的gate.util.InvalidOffsetException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论