net.sf.okapi.common.Event类的使用及代码示例

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

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

Event介绍

[英]Represents an event generated by a filter that implements IFilter.
[中]表示由实现IFilter的筛选器生成的事件。

代码示例

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

@Override
  protected Event handleTextUnit(Event event) {

    // TODO: move to cleaner. create run method

    ITextUnit tu = event.getTextUnit();

    // return event iff tu has text, else remove tu
    if (cleaner.run(tu, targetLocale) == true) {
      return Event.NOOP_EVENT;
    } else {
      return event;
    }
  }
}

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

/**
 * Find in our buffered queue the most recent TextUnit
 * that has an assigned name
 * @return - the TextUnit name, null if not found
 */
public String findMostRecentTextUnitName() {	
  if (tempFilterEventStack.isEmpty()) {
    return null;
  }
  // skip current TextUnit - the one we are currently processing
  for (Event fe : tempFilterEventStack) {
    if (fe.getEventType() == EventType.TEXT_UNIT && fe.getTextUnit().getName() != null) {
      return fe.getTextUnit().getName();
    }
  }
  return null;	
}

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

/**
 * Cancel current processing and add the CANCELED {@link Event} to the event queue.
 */
public void cancel() {
  // flush out all pending events
  filterEvents.clear();
  referencableFilterEvents.clear();
  Event event = new Event(EventType.CANCELED);
  filterEvents.add(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.filters/okapi-filter-autoxliff

@Override
public Event handleEvent(Event event) {
  if (event.isStartDocument()) {
    event.getStartDocument().setFilterParameters(params);
  }
  return delegate.handleEvent(event);
}

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

@Override
public Event handleEvent (Event event) {
  switch ( event.getEventType() ) {
  case START_DOCUMENT:
    processStartDocument(event.getStartDocument());
    break;
  case END_DOCUMENT:
    processEndDocument();
    break;
  case START_GROUP:
  case START_SUBFILTER:
    processStartGroup(event.getStartGroup());
    break;
  case END_GROUP:
  case END_SUBFILTER:
    processEndGroup(event.getEndGroup());
    break;
  case TEXT_UNIT:
    processTextUnit(event.getTextUnit());
    break;
  default:
    break;
  }
  return event;
}

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

@Override
public Event handleEvent (Event event) {
  switch ( event.getEventType() ) {
  case START_DOCUMENT:
    processStartDocument(event.getStartDocument());
    break;
  case END_DOCUMENT:
    close();
    break;
  case TEXT_UNIT:
    processTextUnit(event.getTextUnit());
    break;
  default:
    break;
  }
  return event;
}

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

private Event nextEvent () {
  if ( queue.size() == 0 ) return null;
  if ( queue.peek().getEventType() == EventType.END_DOCUMENT ) {
    parseState = 0; // No more event after
  }
  return queue.poll();
}

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

try {
  xlfReader = new XLIFFFilter();
  xlfReader.open(event.getRawDocument());
  while (filter.hasNext()) {
    Event e = filter.next();
    if (e.getEventType() == EventType.TEXT_UNIT) {
      processTextUnit(e.getTextUnit());

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

public Event next () {
  // Check for cancellation first
  if ( canceled ) {
    queue.clear();
    queue.add(new Event(EventType.CANCELED));
    hasNext = false;
  }
  
  // Parse next if nothing in the queue
  if ( queue.size() == 0 ) {
    parseNext();
  }
  
  // Return the head of the queue
  if ( queue.peek().getEventType() == EventType.END_DOCUMENT ) {
    hasNext = false;
  }
  return queue.poll();
}

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

@Override
public Event handleEvent(Event event) {
  switch (event.getEventType()) {
    case START_DOCUMENT:
      processStartDocument(event.getStartDocument());
      break;
    case DOCUMENT_PART:
      break;
    case START_SUBDOCUMENT:
      processStartSubDocument((StartSubDocument) event.getResource());
      break;
    case END_SUBDOCUMENT:
      processEndSubDocument((Ending) event.getResource());
      break;
    case TEXT_UNIT:

代码示例来源: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/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/okapi-core

GenericSkeleton skel = (GenericSkeleton) tempTextUnit.getResource().getSkeleton();
tempTextUnit.setResource(postProcessTextUnit(tempTextUnit.getTextUnit()));
filterEvents.add(tempTextUnit);
ITextUnit tu = tempTextUnit.getTextUnit();
tu.getSource().getFirstContent().renumberCodes();
for (LocaleId t : tu.getTargetLocales()) {
  tu.getSource().getFirstContent().alignCodeIds(targetFrag);            
return (ITextUnit)tempTextUnit.getResource();

代码示例来源: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 handleEvent(Event event) {
    switch (event.getEventType()) {
    case START_DOCUMENT:			
      simplifier = new ResourceSimplifier(targetLocale);
      simplifier.setOutputEncoding(outputEncoding);
      if (event.getStartDocument() == null) {
        throw new OkapiException("StartDocument resource not set.");
      }
      simplifier.setMultilingual(event.getStartDocument().isMultilingual());
      break;
      
    default:
      break;
    }
    
    if (simplifier != null)
      return simplifier.convert(event);
          
    // Original event
    return event;
  }
}

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

private boolean isStyledReferenceableEvent(ReferenceableEvent referenceableEvent) {
  switch (referenceableEvent.getEvent().getEventType()) {
    case TEXT_UNIT:
      return true;
    case DOCUMENT_PART:
      return referenceableEvent.getEvent().getDocumentPart().getSkeleton() instanceof StyledTextSkeleton;
    default:
      throw new IllegalStateException(UNEXPECTED_STRUCTURE);
  }
}

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

/**
 * Open the nested {@link OpenXMLContentFilter} instance on the specified InputStream,
 * and convert a START_SUBDOCUMENT event for it.
 * @param is input stream
 * @param documentId document identifier
 * @param subDocumentId sub-document identifier
 * @param srcLang the source language
 * @return the START_SUBDOCUMENT Event
 */
protected Event openContentFilter(InputStream is, String documentId, String subDocumentId, LocaleId srcLang) {
  contentFilter.open(new RawDocument(is, StandardCharsets.UTF_8.name(), srcLang));
  Event startDocEvent = contentFilter.next();
  // Change the START_DOCUMENT event to START_SUBDOCUMENT
  StartSubDocument sd = new StartSubDocument(documentId, subDocumentId);
  sd.setName(entry.getName());
  ConditionalParameters clonedParams = params.clone();
  clonedParams.nFileType = contentFilter.getParseType();
  sd.setFilterParameters(clonedParams);
  ZipSkeleton skel = new ZipSkeleton((GenericSkeleton)startDocEvent.getStartDocument().getSkeleton(),
                    zipFile.getZip(), entry);
  return new Event(EventType.START_SUBDOCUMENT, sd, skel);
}

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

@Override
public Event handleEvent (Event event) {
  switch (event.getEventType()) {
  case START_BATCH:
    isDone = true;
    isDone = false;
    filter.open(event.getRawDocument());
        if ( e.getEventType() == EventType.END_DOCUMENT ) {

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

@Override
protected Event handleStartDocument (Event event) {
  // Use target text if reference file is bilingual, otherwise use the source
  useTargetText = event.getStartDocument().isMultilingual();
  // Create the table if possible
  if ( toCopyInput == null ) {
    logger.warn("Second input file is not specified.");
    toCopy = null;
  }
  else {
    // Else: read the file
    readEntriesToCopy();
  }
  return event;
}

相关文章