Class QueryUtil


  • public class QueryUtil
    extends Object
    Collection of helper method for preparing and querying translation resources.
    • Constructor Detail

      • QueryUtil

        public QueryUtil()
    • Method Detail

      • hasCode

        public boolean hasCode()
        Indicates if the last text fragment passed to separateCodesFromText(TextFragment) has codes or not.
        Returns:
        true if the fragment has one or more code, false if it does not.
      • separateCodesFromText

        public String separateCodesFromText​(TextFragment frag)
        Separate and store codes of a given text fragment.
        Parameters:
        frag - the fragment to process. Use createNewFragmentWithCodes(String) to reconstruct the text back with its codes at the end.
        Returns:
        the fragment content stripped of its codes.
      • createNewFragmentWithCodes

        public TextFragment createNewFragmentWithCodes​(String plainText)
        Appends the codes stored apart using separateCodesFromText(TextFragment) at the end of a given plain text. The text fragment provided must be the same and without code modifications, as the one used for the splitting.
        Parameters:
        plainText - new text to use (must be plain)
        Returns:
        the provided fragment, but with the new text and the original codes appended at the end.
      • toCodedHTML

        public List<String> toCodedHTML​(List<TextFragment> frags)
        Converts from coded texts to coded HTML. The resulting strings are also valid XML.
        Parameters:
        frags - the fragments to convert.
        Returns:
        The resulting HTML string.
      • toCodedHTML

        public String toCodedHTML​(TextFragment fragment)
        Converts from coded text to coded HTML. The resulting string is also valid XML.
        Parameters:
        fragment - the fragment to convert.
        Returns:
        The resulting HTML string.
      • fromCodedHTMLToFragment

        public TextFragment fromCodedHTMLToFragment​(String text,
                                                    TextFragment fragment)
        Converts an HTML string created with toCodedHTML(TextFragment) back into a text fragment, but with empty inline codes.
        Parameters:
        text - the HTML string to convert.
        fragment - an optional text fragment where to place the converted content. Any existing codes will be replaced or removed by the codes coming from the HTML string. Use null to create a new fragment.
        Returns:
        the modified or created text fragment.
      • fromCodedHTML

        public String fromCodedHTML​(String htmlText,
                                    TextFragment fragment,
                                    boolean addMissingCodes)
        Converts back a coded HTML to a coded text. (extra span elements are removed).
        Parameters:
        htmlText - the coded HTML to convert back.
        fragment - the original text fragment.
        addMissingCodes - true to added codes that are in the original fragment but not in the HTML string.
        Returns:
        the coded text with its code markers.
      • fromCodedHTML

        public String fromCodedHTML​(String htmlText,
                                    TextFragment fragment,
                                    boolean addMissingCodes,
                                    boolean removeSpans)
        Converts back a coded HTML to a coded text.
        Parameters:
        htmlText - the coded HTML to convert back.
        fragment - the original text fragment.
        addMissingCodes - true to added codes that are in the original fragment but not in the HTML string.
        removeSpans - true to remove extra span HTML codes.
        Returns:
        the coded text with its code markers.
      • fromXLIFF

        public TextFragment fromXLIFF​(Element elem,
                                      TextFragment original)
        Converts back an XLIFF text contained in a given element into a TextFragment.
        Parameters:
        elem - The element containing the XLIFF data.
        original - the original TextFragment (cannot be null).
        Returns:
        the newly created text fragment.
        See Also:
        toXLIFF(TextFragment)
      • removeDuplicates

        public static ArrayList<QueryResult> removeDuplicates​(List<QueryResult> queryResults)
        Removes duplicates based on the Equals method of QueryResult. Preserve the highest ranked query results. For example, duplicate results with the newest creation date are always retained.
        WARNING: order is not preserved!
        Parameters:
        queryResults - the list of QueryResults to process.
        Returns:
        a new list of the QueryResults without duplicates.