Interface LanguageHandler

  • All Known Implementing Classes:
    BCP47LanguageHandler, LowercaseBCP47LanguageHandler, RFC3066LanguageHandler

    public interface LanguageHandler
    An interface defining methods related to verification and normalization of language tags.

    The language handler may optionally provide normalization and verification services for string literals based on the language tags, including translation, grammar and spelling checks. However, this behavior is entirely driven by the user.

    Since:
    1.0
    Version:
    1.0
    Author:
    Peter Ansell, Michael Grove
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String BCP47
      Identifier for the language tag format defined by BCP47, which is referenced by the RDF-1.1 specification.
      static java.lang.String RFC3066
      Identifier for the language tag format defined by RFC3066, which is referenced by the RDF-1.0 specification.
      static java.lang.String RFC4646
      Identifier for the language tag format defined by RFC4646, which obsoletes RFC3066, but which is not referenced by the RDF specification.
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      boolean isRecognizedLanguage​(java.lang.String theLangTag)
      Checks if the given language tag is recognized by this language handler, including cases where the language tag is recognized, but is not yet normalized.
      java.lang.String key()
      A unique key for this language handler
      Literal normalizeLanguage​(java.lang.String theValue, java.lang.String theLang)
      Normalize both the language tag and the language if appropriate.
      java.lang.String normalizeLanguageTag​(java.lang.String theLang)
      Normalize the language tag.
      boolean verifyLanguage​(java.lang.String theValue, java.lang.String theLang)
      Verifies that the language tag is valid, optionally including an automated check on the literal value.
    • Field Detail

      • RFC3066

        static final java.lang.String RFC3066
        Identifier for the language tag format defined by RFC3066, which is referenced by the RDF-1.0 specification.
        See Also:
        Constant Field Values
      • RFC4646

        static final java.lang.String RFC4646
        Identifier for the language tag format defined by RFC4646, which obsoletes RFC3066, but which is not referenced by the RDF specification.
        See Also:
        Constant Field Values
      • BCP47

        static final java.lang.String BCP47
        Identifier for the language tag format defined by BCP47, which is referenced by the RDF-1.1 specification.
        See Also:
        Constant Field Values
    • Method Detail

      • isRecognizedLanguage

        boolean isRecognizedLanguage​(@Nonnull
                                     java.lang.String theLangTag)
        Checks if the given language tag is recognized by this language handler, including cases where the language tag is recognized, but is not yet normalized.
        Parameters:
        theLangTag - The language tag to check.
        Returns:
        True if the language tag is syntactically valid and could be used with verifyLanguage(String, String) and normalizeLanguage(String, String).
      • verifyLanguage

        boolean verifyLanguage​(@Nonnull
                               java.lang.String theValue,
                               @Nonnull
                               java.lang.String theLang)
                        throws InvalidLiteral
        Verifies that the language tag is valid, optionally including an automated check on the literal value.

        This method must only be called after verifying that isRecognizedLanguage(String) returns true for the given language tag.

        Parameters:
        theValue - Literal value matching the given language tag.
        theLang - A language tag that matched with isRecognizedLanguage(String).
        Returns:
        `true` if the language tag is recognized by this language handler, and it is verified to be syntactically valid.
        Throws:
        InvalidLiteral - If the language tag was not recognized.
      • normalizeLanguage

        @Nonnull
        Literal normalizeLanguage​(@Nonnull
                                  java.lang.String theValue,
                                  @Nonnull
                                  java.lang.String theLang)
                           throws InvalidLiteral
        Normalize both the language tag and the language if appropriate.

        This method must only be called after verifying that isRecognizedLanguage(String) returns true for the given language tag, and verifyLanguage(String, String) also returns true for the given language and literal value.

        Parameters:
        theValue - Required literal value to use in the normalization process and to provide the value for the resulting literal.
        theLang - The language tag which is to be normalized. This tag is available in normalized form from the result using Literal.lang().
        Returns:
        A Literal containing the normalized literal value and language tag.
        Throws:
        InvalidLiteral - If the language tag was not recognized or verified, or the literal value could not be normalized due to an error.
      • normalizeLanguageTag

        @Nonnull
        java.lang.String normalizeLanguageTag​(@Nonnull
                                              java.lang.String theLang)
        Normalize the language tag. This function _may_ work even if the language tag is invalid. Use verifyLanguage(String, String) to ensure the language is valid.
        Parameters:
        theLang - The language tag which is to be normalized.
        Returns:
        A normalized language tag.
      • key

        @Nonnull
        java.lang.String key()
        A unique key for this language handler
        Returns:
        A unique `String` key.