net.sf.okapi.common.Event.getResource()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(7.8k)|赞(0)|评价(0)|浏览(123)

本文整理了Java中net.sf.okapi.common.Event.getResource()方法的一些代码示例,展示了Event.getResource()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Event.getResource()方法的具体详情如下:
包路径:net.sf.okapi.common.Event
类名称:Event
方法名:getResource

Event.getResource介绍

[英]Gets the resource associated to this event.
[中]获取与此事件关联的资源。

代码示例

代码示例来源:origin: net.sf.okapi/okapi-core

/**
 * Peek at the most recently created {@link StartSubDocument}
 * 
 * @return the filter event
 */
public StartSubDocument peekMostRecentSubDocument() {
  if (tempFilterEventStack.isEmpty()) {
    return null;
  }
  // the normal stack iterator gives the elements in the wrong order
  int lastIndex = tempFilterEventStack.size() - 1;
  for (int i = lastIndex; i >= 0; i--) {
    Event fe = tempFilterEventStack.get(i);
    if (fe.getEventType() == EventType.START_SUBDOCUMENT) {
      StartSubDocument sd = (StartSubDocument) fe.getResource();
      return sd;
    }
  }
  return null;
}

代码示例来源:origin: net.sf.okapi.steps/okapi-step-common

private void normalizeResourceName (Event event) {
  if ( documentsRoot == null ) return; // Nothing to do
  INameable res = (INameable)event.getResource();
  String name = res.getName();
  if ( Util.isEmpty(name) ) return; // Nothing to do
  name = name.replace('\\', '/');
  if ( name.startsWith(documentsRoot) ) {
    name = name.substring(documentsRoot.length());
  }
  res.setName(name);
}

代码示例来源:origin: net.sf.okapi.filters/okapi-filter-versifiedtxt

private void processStartSubDocument(Event event) {
  try {
    StartSubDocument ssd = (StartSubDocument) event.getResource();
    writer.write("|c" + ssd.getName() + linebreak);
  } catch (IOException e) {
    throw new OkapiIOException("Error writing subdocument (|cName).", e);
  }
}

代码示例来源:origin: net.sf.okapi.steps/okapi-step-common

@Override
  protected Event handleCustom(Event event) {
    Custom c = (Custom)event.getResource();
    rules = c.getAnnotation(SimplifierRulesAnnotaton.class);
    return super.handleCustom(event);
  }
}

代码示例来源:origin: net.sf.okapi.filters/okapi-filter-po

private void processStartSubDocument (Event event) {
  if ( forExtractMerge ) {
    StartSubDocument ssd = (StartSubDocument)event.getResource();
    pushCrumb(SUBDOCUMENT_CRUMB+ssd.getId());
  }
}

代码示例来源:origin: net.sf.okapi.filters/okapi-filter-transtable

private void processStartGroup (Event event) {
  StartGroup sg = (StartGroup)event.getResource();
  pushCrumb(GROUP_CRUMB+sg.getId());
}

代码示例来源:origin: net.sf.okapi.steps/okapi-step-common

@Override
  protected Event handleCustom(Event event) {
    Custom c = (Custom)event.getResource();
    rules = c.getAnnotation(SimplifierRulesAnnotaton.class);
    return super.handleCustom(event);
  }
}

代码示例来源:origin: net.sf.okapi.filters/okapi-filter-pensieve

private void handleStartDocument (Event event) {
  Util.createDirectories(directory + File.separator);
  // TODO: Move this check at the pensieve package level
  File file = new File(directory + File.separator + "segments.gen");
  // Create a new index only if one does not exists yet
  // If one exists we pass false to append to it
  writer = TmWriterFactory.createFileBasedTmWriter(directory, !file.exists());
  StartDocument sd = (StartDocument) event.getResource();
  srcLoc = sd.getLocale();
}

代码示例来源:origin: net.sf.okapi.filters/okapi-filter-transtable

private void processStartSubDocument (Event event) {
  StartSubDocument ssd = (StartSubDocument)event.getResource();
  pushCrumb(SUBDOCUMENT_CRUMB+ssd.getId());
}

代码示例来源:origin: net.sf.okapi.steps/okapi-step-generatesimpletm

@Override
protected Event handleStartDocument (Event event) {
  StartDocument sd = (StartDocument)event.getResource();
  fileName = Util.getFilename(sd.getName(), true);
  isMultilingual = sd.isMultilingual();
  if(!isMultilingual){
    logger.warn("File {} is not processed as a multiLingual file and cannot be used to populate the SimpleTm.", fileName);
  } 
  
  return event;
}

代码示例来源:origin: net.sf.okapi.filters/okapi-filter-po

private void processStartGroup (Event event) {
  group++;
  StartGroup sg = (StartGroup)event.getResource();
  if (( sg.getType() != null ) && sg.getType().equals("x-gettext-plurals") ) {
    pluralGroup = group;
    plurals.clear();
  }
  if ( forExtractMerge ) {
    pushCrumb(GROUP_CRUMB+sg.getId());
  }
}

代码示例来源:origin: net.sf.okapi.filters/okapi-filter-regex

private void addSkeletonToQueue (String data,
  boolean forceNewEntry)
{
  GenericSkeleton skel;
  if ( !forceNewEntry && ( queue.size() > 0 )) {
    if ( queue.getLast().getResource() instanceof DocumentPart ) {
      // Append to the last queue entry if possible
      skel = (GenericSkeleton)queue.getLast().getResource().getSkeleton();
      skel.append(data.replace("\n", lineBreak));
      return;
    }
  }
  // Else: create a new skeleton entry
  skel = new GenericSkeleton(data.replace("\n", lineBreak));
  queue.add(new Event(EventType.DOCUMENT_PART,
    new DocumentPart(otherId.createId(), false, skel)));
}

代码示例来源:origin: net.sf.okapi.steps/okapi-step-common

@Override
  public Event handleRawDocument (Event event) {
    try (RawDocument rawDoc = (RawDocument)event.getResource();) {				
      StreamUtil.copy(rawDoc.getStream(), outStream);                
    }
    catch ( Throwable e ) {
      throw new OkapiIOException("Error copying a RawDocument to output stream.", e);
    }
    
    // this steps writes RawDocument then eats the event
    return Event.NOOP_EVENT;
  }
}

代码示例来源:origin: net.sf.okapi.steps/okapi-step-segmentation

@Override
protected Event handleCustom (Event event) {
  Custom r = (Custom)event.getResource();
  if (r.getAnnotation(DeepenSegmentationAnnotaton.class) != null) {
    params.setOverwriteSegmentation(false);
    params.setDeepenSegmentation(true);
  }
  return event;
}

代码示例来源:origin: net.sf.okapi/okapi-core

/**
 * Appends text to the first data part of the skeleton.
 * 
 * @param text
 *            the text to happend.
 * 
 * @throws OkapiIllegalFilterOperationException if we try to perform an invalid operation.
 */
public void appendToFirstSkeletonPart(String text) {
  Event tempTextUnit = peekTempEvent();
  GenericSkeleton skel = (GenericSkeleton) tempTextUnit.getResource().getSkeleton();
  if (skel==null) {
    skel = new GenericSkeleton();
    tempTextUnit.getResource().setSkeleton(skel);
  }
  skel.appendToFirstPart(text);
}

代码示例来源:origin: net.sf.okapi/okapi-core

/**
 * Is the current buffered {@link Event} a complex {@link TextUnit}? A complex TextUnit is one which carries along
 * with it it's surrounding formatting or skeleton such <p> text </p> or <title> text </title>
 * 
 * @return true, if current {@link Event} is a complex text unit, false otherwise.
 */
public boolean isCurrentComplexTextUnit() {
  Event e = peekTempEvent();
  if (e != null && e.getEventType() == EventType.TEXT_UNIT && e.getResource().getSkeleton() != null) {
    return true;
  }
  return false;
}

代码示例来源:origin: net.sf.okapi.filters/okapi-filter-transtable

private void processStartDocument (Event event) {
  try {
    StartDocument sd = (StartDocument)event.getResource();
    // Create the output
    createWriter(sd);
    // Writer header
    writer.write(String.format("%s%s\t%s\t%s"+LINEBREAK, SIGNATURE, VERSION,
      sd.getLocale().toString(), language.toString()));
    crumbs = CRUMBS_PREFIX;
  }
  catch ( IOException e ) {
    throw new OkapiIOException("Error writing the header.", e);
  }
}

代码示例来源:origin: net.sf.okapi.steps/okapi-step-common

@Override
public Event handleRawDocument (Event event) {
  RawDocument rawDoc = null;
  try {
    rawDoc = (RawDocument)event.getResource();
    File outFile = new File(outputURI);
    Util.createDirectories(outFile.getAbsolutePath());                
    StreamUtil.copy(rawDoc.getStream(), outFile);                
  }
  catch ( Throwable e ) {
    throw new OkapiIOException("Error writing or copying a RawDocument.", e);
  } finally {
    if (rawDoc != null) {
      rawDoc.close();
    }
  }
  // this steps writes RawDocument then eats the event
  return Event.NOOP_EVENT;
}

代码示例来源:origin: net.sf.okapi.steps/okapi-step-wordcount

private IResource createResource(Event event) {
  if (event == null) return null;
  
  IResource res = event.getResource();
  if (res != null) return res;
  
  switch (event.getEventType()) {
  case END_BATCH:
  case END_BATCH_ITEM:
  case END_DOCUMENT:
  case END_SUBDOCUMENT:
  case END_GROUP:
    res = new Ending(gen.createId());
    event.setResource(res);
    break;
  default:
    break;			
  }
  
  return res;
}

代码示例来源:origin: net.sf.okapi.steps/okapi-step-wordcount

protected void saveToMetrics(Event event, Counts count) {
  if (event == null || count == null) return;
  if (count.isAllZeros()) return;
  
  IWithAnnotations res = (IWithAnnotations) event.getResource();
  if (res == null) {
    res = (IWithAnnotations) createResource(event);
  }
  if (res == null) return;
  
  MetricsAnnotation ma = res.getAnnotation(MetricsAnnotation.class);
  
  if (ma == null) {			
    ma = new MetricsAnnotation();
    res.setAnnotation(ma);
  }
  
  Metrics m = ma.getMetrics();        
  if (m == null) return;
        
  saveCount(m, count);
}

相关文章