private void outputITSAttributes (GenericAnnotations anns, int quoteMode, boolean escapeGT, StringBuilder output, boolean inline, boolean mrk, LocaleId trgLocId) { if ( itsCont == null ) { itsCont = new ITSContent(chsEnc, false, true); } itsCont.outputAnnotations(anns, output, inline, mrk, true, trgLocId); standoff = itsCont.getStandoff(); }
/** * Gets the IRI for a given data category, for the current content. * @param dataCategory the data category to look up. * @return the IRI for the given data, or null. */ public String getAnnotatorRef (String dataCategory) { String tmp = annotatorsRef.peek(); if ( tmp == null ) return null; return ITSContent.annotatorsRefToMap(tmp).get(dataCategory); }
/** * Reads and pushes the annotatorsRef information in the context stack. * <p>The method looks if there is an ITS annotatorsRef attribute in the current node * of the provided reader (the node is assumed to be an element) * and uses it if present. It uses the parent context otherwise. */ public void readAndPush () { String val = reader.getAttributeValue(Namespaces.ITS_NS_URI, "annotatorsRef"); if ( val != null ) { // Update the existing values if needed val = ITSContent.updateAnnotatorsRef(annotatorsRef.peek(), val); } else { val = annotatorsRef.peek(); } annotatorsRef.push(val); }
/** * Output the standoff markup for this object and clear it afterward. * This is the same as calling <code>this.writeStandoffLQI(this.getStandoff());</code> then <code>this.clearStandoff()</code> * @return the generated output. */ public String writeStandoffLQI () { String res = writeStandoffLQI(getStandoff()); clearStandoff(); return res; }
/** * Gets the ITS annotator reference for a given data category on a given object. * @param dataCategory the data category identifier. * @param nameable the nameable object where to look for the annotator. * @return the value of the annotator reference for the given data category, * or null if there is none declared. * @see #getAnnotatorsRef(IWithAnnotations) * @see #getAnnotatorRef(String, String) */ public static String getAnnotatorRef (String dataCategory, INameable nameable) { return getAnnotatorRef(dataCategory, getAnnotatorsRef(nameable)); }
printITSStringAttribute(ann.getString(GenericAnnotationType.TA_CLASS), (isHTML5 ? "ta-class" : "taClass"), output); printITSDoubleAttribute(ann.getDouble(GenericAnnotationType.TA_CONFIDENCE), (isHTML5 ? "ta-confidence" : "taConfidence"), output); printITSStringAttribute(ann.getString(GenericAnnotationType.TA_IDENT), (isHTML5 ? "ta-ident" : "taIdent"), output); printITSStringAttribute(ann.getString(GenericAnnotationType.TA_SOURCE), (isHTML5 ? "ta-source" : "taSource"), output); hasTerm = true; if ( !(isXLIFF && inline) ) { printITSBooleanAttribute(true, "term", output); printITSExtDoubleAttribute(ann.getDouble(GenericAnnotationType.TERM_CONFIDENCE), "termConfidence", output); printITSDoubleAttribute(ann.getDouble(GenericAnnotationType.TERM_CONFIDENCE), (isHTML5 ? "term-confidence" : "termConfidence"), output); printITSExtStringAttribute(value, "termInfo"+ref, output); printITSStringAttribute(value, " "+prefix+(isHTML5 ? "term-info" : "termInfo")+ref, output); printITSStringAttribute(ann.getString(GenericAnnotationType.ALLOWEDCHARS_VALUE), (isHTML5 ? "allowed-characters" : "allowedCharacters"), output); printITSIntegerAttribute(ann.getInteger(GenericAnnotationType.STORAGESIZE_SIZE), (isHTML5 ? "storage-size" : "storageSize"), output); String tmp = ann.getString(GenericAnnotationType.STORAGESIZE_ENCODING);
pushAnnotatorsRef(ITSContent.getAnnotatorsRef(tu)); if ( ann != null ) { String value = ann.getString(GenericAnnotationType.LOCFILTER_VALUE); if ( !ITSContent.isExtendedMatch(value, trgLoc.toBCP47()) ) { writer.writeAttributeString("translate", "no"); writeAnnotatorsRefIfNeeded(); sbITS.setLength(0); itsContForUnit.outputAnnotations(tu.getAnnotation(GenericAnnotations.class), sbITS, false, false, false, trgLoc); itsContForUnit.outputAnnotations( (GenericAnnotations)tu.getAnnotation(ITSProvenanceAnnotations.class), sbITS, false, false, false, trgLoc); pushAnnotatorsRef(ITSContent.getAnnotatorsRef(tc)); writeAnnotatorsRefIfNeeded(); sbITS.setLength(0); itsContForSrcCont.outputAnnotations(tc.getAnnotation(GenericAnnotations.class), sbITS, false, false, false, null); itsContForSrcCont.outputAnnotations( (GenericAnnotations)tc.getAnnotation(ITSLQIAnnotations.class), sbITS, false, false, false, null); itsContForSrcCont.outputAnnotations( (GenericAnnotations)tc.getAnnotation(ITSProvenanceAnnotations.class), sbITS, false, false, false, null); pushAnnotatorsRef(ITSContent.getAnnotatorsRef(tc)); writeAnnotatorsRefIfNeeded();
@Override public String processDocumentPart (DocumentPart resource) { GenericSkeleton skel = (GenericSkeleton)resource.getSkeleton(); if ( skel != null ) { GenericSkeletonPart firstPart = skel.getFirstPart(); StringBuilder firstPartData = firstPart.getData(); // Is it a standoff placeholder if ( firstPartData.toString().equals(ITSContent.STANDOFFMARKER) ) { firstPart.setData(""); // Clear the marker in all cases // And add the markup if there is something to output if ( !Util.isEmpty(standoff) ) { if ( itsCont == null ) { itsCont = new ITSContent(encoderManager.getCharsetEncoder(), true, false); } firstPart.append(itsCont.writeStandoffLQI(standoff)); firstPart.append(itsCont.writeStandoffProvenance(standoff)); } } clarifyTextDirection(firstPartData); } // Then do the normal process return super.processDocumentPart(resource); }
private String writeStandoffLQI (List<GenericAnnotations> list) { if ( Util.isEmpty(list) ) return ""; if ( itsContForUnit == null ) { itsContForUnit = new ITSContent(xliffCont.getCharsetEncoder(), false, true); } return itsContForUnit.writeStandoffLQI(list); }
/** * Updates a set of annotator references with new values. * @param oldValues the set of old values (can be null). * @param newValues the set of new values (can be null). * @return the updated new set of values. * If the given set of new values is null, the values returned are the old ones. */ public static String updateAnnotatorsRef (String oldValues, String newValues) { // if there are no new values provided, we don't change anything if ( newValues == null ) return oldValues; // Update each data category modified by this annotators reference attribute Map<String, String> oldMap = ITSContent.annotatorsRefToMap(oldValues); Map<String, String> newMap = ITSContent.annotatorsRefToMap(newValues); oldMap.putAll(newMap); // Add or override if needed return ITSContent.mapToAnnotatorsRef(oldMap); }
/** * Indicates if the current node is to be extracted according its ITS state. * @return true if it is to be extracted, false otherwise. */ private boolean extract () { // Check ITS translate if ( !trav.getTranslate(null) ) return false; // Check ITS locale filter String list = trav.getLocaleFilter(); // null is none-defined, so default is '*' if (( list == null ) || list.equals("*") ) return true; if ( list.isEmpty() || list.equals("!*") ) return false; // More info for extended language range/filtering here: // http://www.rfc-editor.org/rfc/bcp/bcp47.txt if ( trgLangCode == null ) { // Log a warning that the data category cannot be used logger.warn("No target locale specified: Cannot use the provided ITS Locale Filter data category."); return true; } // Now check with one or more codes return ITSContent.isExtendedMatch(list, trgLangCode); }
itsContForUnit = new ITSContent(xliffCont.getCharsetEncoder(), false, true); itsContForSrcCont = new ITSContent(xliffCont.getCharsetEncoder(), false, true); itsContForTrgCont = new ITSContent(xliffCont.getCharsetEncoder(), false, true); itsContForAltTrgCont = new ITSContent(xliffCont.getCharsetEncoder(), false, true);
pushAnnotatorsRef(ITSContent.getAnnotatorsRef(alt.getTarget())); writer.writeStartElement("target"); writer.writeAttributeString("xml:lang", alt.getTargetLocale().toBCP47()); writeAnnotatorsRefIfNeeded(); StringBuilder tmp = new StringBuilder(); itsContForAltTrgCont.outputAnnotations(alt.getTarget().getAnnotation(GenericAnnotations.class), tmp, false, false, false, null); writer.appendRawXML(tmp.toString());
public void clearStandoff () { standoff = null; if ( itsCont != null ) itsCont.clearStandoff(); }
/** * Indicates if a given language tag matches at least one item of a list of extended language ranges. * <p>Based on the algorithm described at: http://tools.ietf.org/html/rfc4647#section-3.3.2 * @param langRanges the list of extended language ranges (with optional '!' prefix for 'exclude') * @param langTag the language tag. * @return true if the language tag results in inclusion, false if it results in exclusion. */ public static boolean isExtendedMatch (String langRanges, String langTag) { boolean result = true; if ( langRanges.startsWith("!") ) { langRanges = langRanges.substring(1); result = false; } for ( String langRange : ListUtil.stringAsArray(langRanges.toLowerCase()) ) { if ( doesLangTagMacthesLangRange(langRange, langTag) ) return result; } return !result; }
@Override public String getAnnotatorRef (String dc) { validateDataCategoryNames(dc); String tmp = trace.peek().annotatorsRef; if ( tmp == null ) return null; Map<String, String> map = ITSContent.annotatorsRefToMap(tmp); return map.get(dc); }
/** * Updates the current ITS annotators references based on a given set of values. * @param values the annotators references values to use to update the existing ones. * The annotation will be output in the next element that can carry it. */ public void setAnnotatorsRef (String values) { // Push the new values of the annotators based on possible annotation at the TU level String oldValues = annotatorsRef.pop(); String newValues = ITSContent.updateAnnotatorsRef(oldValues, values); annotatorsRef.push(newValues); // Establish if the updated values have changed (only if it's no needed yet) if ( !needAnnotatorsRef ) { if ( oldValues == null ) { needAnnotatorsRef = (newValues != null); } else { if ( newValues != null ) { needAnnotatorsRef = !oldValues.equals(newValues); } else { needAnnotatorsRef = true; } } } }
Map<String, String> map = ITSContent.annotatorsRefToMap(value); for ( String dc : map.keySet() ) { validateDataCategoryNames(dc);
trace.peek().annotatorsRef = ITSContent.updateAnnotatorsRef( trace.peek().annotatorsRef, getFlagData(data, FP_ANNOTATORSREF_DATA));
GenericAnnotation.addAnnotation(code, new GenericAnnotation(GenericAnnotationType.ANNOT, GenericAnnotationType.ANNOT_VALUE, value)); annotatorsRef = ITSContent.annotatorsRefToMap(value);