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

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

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

Event.getStartDocument介绍

[英]Convenience method returns the IResource as a StartDocument. The caller should confirm the Event type using isStartDocument before calling this method.
[中]便利方法将IResource作为StartDocument返回。调用方应在调用此方法之前使用isStartDocument确认事件类型。

代码示例

代码示例来源: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;
}

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

private void processStartDocument(Event event) {
  try {
    StartDocument sd = event.getStartDocument();
    
    // Create the output
    createWriter(sd);
    // Writer header
    writer.write("|b" + sd.getName() + linebreak);
  } catch (IOException e) {
    throw new OkapiIOException("Error writing the versified text file header.", e);
  }
}

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

@Override
protected Event handleStartDocument (Event event) {
  StartDocument sd = event.getStartDocument();
  IParameters prm = sd.getFilterParameters();
  String paramsData = null;
  if ( prm != null ) {
    paramsData = prm.toString();
  }
  String relativeInput = new File(inputRootDir).toURI().relativize(inputURI).getPath();
  String relativeOutput = new File(outputRootDir).toURI().relativize(outputURI).getPath();
  writer.setDocumentInformation(relativeInput, filterConfigId, paramsData, sd.getEncoding(),
    relativeOutput, outputEncoding, sd.getFilterWriter().getSkeletonWriter());
  return writer.handleEvent(event);
}

代码示例来源: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-autoxliff

@Override
public Event next() {
  if (delegate != null) {
    Event e = delegate.next();
    if (e.isStartDocument()) {
      StartDocument sd = e.getStartDocument();
      sd.setFilterParameters(getParameters());
    }
    return e;
  }
  return null;
}

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

protected void processStartDocument (Event event) {
  StartDocument sd = event.getStartDocument();
  String docPath = sd.getName()==null ? "" : sd.getName();
  if (System.getProperty("os.name").startsWith("Windows") && Pattern.matches("^/[A-Z]:.*$", docPath))
    docPath = docPath.substring(1);
  
  String ori = manifest.getTempOriginalDirectory();
  if ( Util.isEmpty(ori) ) return; // No copy to be done
  
  // Else: copy the original
  MergingInfo info = manifest.getItem(docId);
  String inputPath =  exists(docPath) ? docPath : manifest.getInputRoot() + info.getRelativeInputPath();
  String outputPath = ori + info.getRelativeInputPath();
  StreamUtil.copy(inputPath, outputPath, false);
}

代码示例来源: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.steps/okapi-step-segmentation

@Override
protected Event handleStartDocument (Event event) {
  if ( params.getSegmentSource() || params.getSegmentTarget() ) {
    // Possibly force the output segmentation, but only if we do any segmentation
    if ( params.getForcesegmentedOutput() ) {
      // Force to show the segments when possible
      IParameters prm = event.getStartDocument().getFilterParameters();
      if ( prm != null ) {
        prm.setInteger("outputSegmentationType", 3);
      }
    }
  }
  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.steps/okapi-step-rainbowkit

StartDocument sd = event.getStartDocument();
try {
  Util.createDirectories(path);

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

if (e.isNoop()) continue; // Get next filter event
if (e.isStartDocument()) {
  StartDocument sd = e.getStartDocument();
  sd.setFilterParameters(this.getParameters()); // Replace internal filter's parameters with this one's

代码示例来源: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-idbasedaligner

useTargetText = event.getStartDocument().isMultilingual();

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

switch (event.getEventType()) {
  case START_DOCUMENT:
    processStartDocument(event.getStartDocument());
    break;
  case DOCUMENT_PART:

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

@Override
protected Event handleStartDocument(Event event) {
  // Initial document is expected to be a manifest
  StartDocument sd = event.getStartDocument();
  info = sd.getAnnotation(MergingInfo.class);
  if (info == null) {
    throw new OkapiBadFilterInputException("Start document is missing the merging info annotation.");
  }
  Manifest manifest = sd.getAnnotation(Manifest.class);
  if (manifest == null) {
    throw new OkapiBadFilterInputException("Start document is missing the manifest annotation.");
  }
  // Create the merger (for each new manifest)
  boolean alwaysForceTargetLocale = Manifest.EXTRACTIONTYPE_ONTRAM.equals(info.getExtractionType());
  LocaleId targetLocaleToUse;
  if (params.getForceTargetLocale() || alwaysForceTargetLocale) {
    targetLocaleToUse = targetLocale;
  } else {
    targetLocaleToUse = null;
  }
  useSkel = info.getUseSkeleton();
  merger = new Merger(manifest, fcMapper, params.getPreserveSegmentation(), targetLocaleToUse,
      params.getReturnRawDocument(), params.getOverrideOutputPath());
  return merger.startMerging(info, 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.steps/okapi-step-rainbowkit

@Override
protected void processStartDocument (Event event) {
  super.processStartDocument(event);
  
  writer = new XLIFFWriter();
  referents = new LinkedHashMap<String, String>();
  MergingInfo item = manifest.getItem(docId);
  rawDocPath = manifest.getTempSourceDirectory() + item.getRelativeInputPath() + ".xlf";
  // Set the writer's options
  writer.setWithOriginalData(options.getwithOriginalData());
  writer.setUseIndentation(true);
  // Create the writer
  trgLoc = manifest.getTargetLocale();
  Util.createDirectories(rawDocPath); //TODO: This should be done by the writer. To change when it's implemented properly.
  writer.create(new File(rawDocPath), manifest.getSourceLocale().toBCP47(), trgLoc.toBCP47());
  StartXliffData sxd = new StartXliffData(null);
  ITSWriter.addDeclaration(sxd);
  writer.writeStartDocument(sxd, null);
  // Original: use the document name if there is one (null is allowed)
  // For now we don't set ID for the files, the writer will generate them 
  StartFileData sfd = new StartFileData(null);
  sfd.setOriginal(event.getStartDocument().getName());
  writer.setStartFileData(sfd);
}

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

"The start document event can't be found in the skeleton file.");
} else {
  StartDocument sd = skelEvent.getStartDocument();

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

@Override
protected void processStartDocument (Event event) {
  super.processStartDocument(event);
  
  writer = new XLIFFWriter();
  writer.setOptions(manifest.getTargetLocale(), "UTF-8");
  MergingInfo item = manifest.getItem(docId);
  rawDocPath = manifest.getTempSourceDirectory() + item.getRelativeInputPath() + ".xlf";
  writer.setOutput(rawDocPath); // Not really used, but doesn't hurt just in case
  XLIFFWriterParameters paramsXliff = (XLIFFWriterParameters)writer.getParameters();
  // Set the writer's options
  if ( forOmegat ) {
    // Direct setting for the writer (not an XLIFF option)
    paramsXliff.setUseSourceForTranslated(true);
  }
  paramsXliff.setPlaceholderMode(options.getPlaceholderMode());
  paramsXliff.setCopySource(options.getCopySource());
  paramsXliff.setIncludeAltTrans(options.getIncludeAltTrans());
  paramsXliff.setSetApprovedAsNoTranslate(options.getSetApprovedAsNoTranslate());
  paramsXliff.setIncludeNoTranslate(options.getIncludeNoTranslate());
  paramsXliff.setIncludeCodeAttrs(options.getIncludeCodeAttrs());
  paramsXliff.setIncludeIts(options.getIncludeIts());
  paramsXliff.setEscapeGt(options.getEscapeGT());
  
  StartDocument sd = event.getStartDocument();
  writer.create(rawDocPath, null, manifest.getSourceLocale(), manifest.getTargetLocale(),
    sd.getMimeType(), item.getRelativeInputPath(), null);
}

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

switch ( event.getEventType() ) {
case START_DOCUMENT:
  processStartDocument(locale, encoding, event.getStartDocument());
  break;
case END_DOCUMENT:

相关文章