Class LiteralImpl

java.lang.Object
com.github.owlcs.ontapi.owlapi.OWLObjectImpl
com.github.owlcs.ontapi.owlapi.objects.LiteralImpl
All Implemented Interfaces:
AsNode, Serializable, Comparable<org.semanticweb.owlapi.model.OWLObject>, org.semanticweb.owlapi.model.HasAnnotationPropertiesInSignature, org.semanticweb.owlapi.model.HasAnnotationValue, org.semanticweb.owlapi.model.HasAnonymousIndividuals, org.semanticweb.owlapi.model.HasClassesInSignature, org.semanticweb.owlapi.model.HasComponents, org.semanticweb.owlapi.model.HasContainsEntityInSignature, org.semanticweb.owlapi.model.HasDataPropertiesInSignature, org.semanticweb.owlapi.model.HasDatatypesInSignature, org.semanticweb.owlapi.model.HasHashIndex, org.semanticweb.owlapi.model.HasIndex, org.semanticweb.owlapi.model.HasIndividualsInSignature, org.semanticweb.owlapi.model.HasLang, org.semanticweb.owlapi.model.HasObjectPropertiesInSignature, org.semanticweb.owlapi.model.HasSignature, org.semanticweb.owlapi.model.IsAnonymous, org.semanticweb.owlapi.model.OWLAnnotationObject, org.semanticweb.owlapi.model.OWLAnnotationValue, org.semanticweb.owlapi.model.OWLLiteral, org.semanticweb.owlapi.model.OWLObject, org.semanticweb.owlapi.model.OWLPrimitive, org.semanticweb.owlapi.model.OWLPropertyAssertionObject
Direct Known Subclasses:
ONTLiteralImpl

public class LiteralImpl extends OWLObjectImpl implements org.semanticweb.owlapi.model.OWLLiteral, AsNode
An ONT-API implementation of OWLLiteral, encapsulated Jena Literal Label.

Created by @szz on 06.09.2018.

See Also:
  • Field Details

    • typeMapper

      protected static final org.apache.jena.datatypes.TypeMapper typeMapper
    • label

      protected final transient org.apache.jena.graph.impl.LiteralLabel label
  • Constructor Details

    • LiteralImpl

      protected LiteralImpl(org.apache.jena.graph.impl.LiteralLabel label)
  • Method Details

    • createLiteral

      public static LiteralImpl createLiteral(String s)
    • createLiteral

      public static LiteralImpl createLiteral(String val, String lang)
      Creates a literal impl by the given lexical from and language tag. The method normalises language tag to the trimmed lower-case form. Notice that language tag in general case may contain upper-case letters, and two similar but different strings are not equal. To create a literal with the retention of the syntax of a language-tag, use methods newLiteral(LiteralLabel) or newLiteral(String, String, OWLDatatype)
      Parameters:
      val - String, lexical form, not null
      lang - String, or null for Plain Literals
      Returns:
      LiteralImpl
      See Also:
    • createLiteral

      public static LiteralImpl createLiteral(int i)
      Creates a literal impl wrapping the given int number.
      Parameters:
      i - int
      Returns:
      LiteralImpl
    • createLiteral

      public static LiteralImpl createLiteral(boolean b)
      Creates a literal impl wrapping the given boolean primitive.
      Parameters:
      b - boolean
      Returns:
      LiteralImpl
    • createLiteral

      public static LiteralImpl createLiteral(double d)
      Creates a literal impl wrapping the given double number.
      Parameters:
      d - double
      Returns:
      LiteralImpl
    • createLiteral

      public static LiteralImpl createLiteral(float f)
      Creates a literal impl wrapping the given float number.
      Parameters:
      f - float
      Returns:
      LiteralImpl
    • createLiteral

      public static LiteralImpl createLiteral(String txt, org.semanticweb.owlapi.model.OWLDatatype owl)
      Creates a literal impl by the given string and OWL Datatype. If the datatype is rdf:PlainLiteral or rdf:langString the method will parse and normalize datatype from the first (String) argument, see createLiteral(String, String) description. If the datatype is xsd:string, then no parsing is performed and the returned literal will have the same lexical form as specified. In other cases the string is parsed, and the lexical form may differ from what was specified. For example, if the input are "1e-07" and xsd:double, the output will be "1.OE7"^^xsd:double.
      Parameters:
      txt - String, not null
      owl - OWLDatatype, not null
      Returns:
      LiteralImpl
      See Also:
    • normalizeLanguageTag

      public static String normalizeLanguageTag(String lang)
      Normalises the language tag
      Parameters:
      lang - String, possible null
      Returns:
      String
      See Also:
    • parseBooleanLiteral

      public static LiteralImpl parseBooleanLiteral(String txt)
    • parseBoolean

      public static boolean parseBoolean(String txt)
    • parseDoubleLiteral

      public static LiteralImpl parseDoubleLiteral(String txt, org.semanticweb.owlapi.model.OWLDatatype dt)
    • parseFloatLiteral

      public static LiteralImpl parseFloatLiteral(String txt, org.semanticweb.owlapi.model.OWLDatatype dt)
    • parseIntegerLiteral

      public static LiteralImpl parseIntegerLiteral(String txt, org.semanticweb.owlapi.model.OWLDatatype dt)
    • asONT

      public static LiteralImpl asONT(org.semanticweb.owlapi.model.OWLLiteral literal)
      Converts any instance of OWLLiteral to the ONT-API Literal implementation.
      Parameters:
      literal - OWLLiteral
      Returns:
      LiteralImpl
    • newLiteral

      public static LiteralImpl newLiteral(String txt, String lang, org.semanticweb.owlapi.model.OWLDatatype owl)
      Creates an LiteralImpl instance by string value and OWL Datatype. This method works with Jena Type Mapper, but it does not change it.
      Parameters:
      txt - String, not null
      lang - String, can be null
      owl - OWLDatatype, not null
      Returns:
      LiteralImpl
    • getRDFDatatype

      public static org.apache.jena.datatypes.RDFDatatype getRDFDatatype(String uri)
      Gets the RDFDatatype for the given uri.
      Parameters:
      uri - String, not null
      Returns:
      RDFDatatype
    • newLiteral

      public static LiteralImpl newLiteral(Object lex, String lang, org.apache.jena.datatypes.RDFDatatype dt)
      Creates an LiteralImpl instance with the given lexical form, language tag and RDF Datatype.
      Parameters:
      lex - String, not null
      lang - String or null for plain or typed literals
      dt - RDFDatatype, may be null in some circumstances
      Returns:
      LiteralImpl
    • newLiteral

      public static LiteralImpl newLiteral(org.apache.jena.graph.impl.LiteralLabel label)
      Creates an LiteralImpl instance for the specifies LiteralLabel.
      Parameters:
      label - LiteralLabel, not null
      Returns:
      LiteralImpl
    • calcLiteralLabelHashCode

      protected static int calcLiteralLabelHashCode(org.apache.jena.graph.impl.LiteralLabel label)
      Calculates a hash-code for lexical form. The original (OWL-API) logic is preserved.
      Parameters:
      label - LiteralLabel, not null
      Returns:
      int
    • calcHashCode

      protected static int calcHashCode(int index, org.apache.jena.graph.impl.LiteralLabel label, org.semanticweb.owlapi.model.OWLDatatype datatype, String lang)
      Calculates a hash-code for LiteralImpl given as its components.
      Parameters:
      index - int, constant, HasHashIndex.hashIndex()
      label - LiteralLabel, not null
      datatype - OWLDatatype, not null
      lang - String, not null
      Returns:
      int
    • equals

      public static boolean equals(org.apache.jena.graph.impl.LiteralLabel left, org.apache.jena.graph.impl.LiteralLabel right)
      Answers true if the argument-literals are equal to each other and false otherwise.
      Parameters:
      left - LiteralLabel, can be null
      right - LiteralLabel, can be null
      Returns:
      boolean
    • getDatatypeURI

      public static String getDatatypeURI(org.apache.jena.graph.impl.LiteralLabel label)
      Gets the valid (in OWL-API sense) datatype URI from the given label.
      Parameters:
      label - LiteralLabel, not null
      Returns:
      String
    • asNode

      public org.apache.jena.graph.Node asNode()
      Description copied from interface: AsNode
      Answers the Node associated with this object.
      Specified by:
      asNode in interface AsNode
      Returns:
      RDF Graph Node, cannot be null
    • getLiteralLabel

      public org.apache.jena.graph.impl.LiteralLabel getLiteralLabel()
      Returns a Jena Literal Label, that is encapsulated by this object.
      Returns:
      LiteralLabel
    • getLiteral

      public String getLiteral()
      Specified by:
      getLiteral in interface org.semanticweb.owlapi.model.OWLLiteral
    • getLang

      public String getLang()
      Specified by:
      getLang in interface org.semanticweb.owlapi.model.HasLang
      Specified by:
      getLang in interface org.semanticweb.owlapi.model.OWLLiteral
    • getDatatypeURI

      public String getDatatypeURI()
      Returns the datatype URI. For a lang-literal the datatype URI is rdf:langString. For a plain-literal the datatype URI is xsd:string.
      Returns:
      String, cannot be null
    • getDatatype

      public org.semanticweb.owlapi.model.OWLDatatype getDatatype()
      Returns the OWL-API datatype parsed from the encapsulated LiteralLabel. Please note: in the special case of no-lang PlainLiteral (e.g. '...'^^rdf:PlainLiteral) the method returns InternalizedEntities.XSD_STRING, although the encapsulated label may contain RDF.PlainLiteral type.
      Specified by:
      getDatatype in interface org.semanticweb.owlapi.model.OWLLiteral
      Returns:
      OWLDatatype
    • hasLang

      public boolean hasLang()
      Specified by:
      hasLang in interface org.semanticweb.owlapi.model.OWLLiteral
    • hasLang

      public boolean hasLang(@Nullable String lang)
      Specified by:
      hasLang in interface org.semanticweb.owlapi.model.OWLLiteral
    • isRDFPlainLiteral

      public boolean isRDFPlainLiteral()
      Specified by:
      isRDFPlainLiteral in interface org.semanticweb.owlapi.model.OWLLiteral
    • isInteger

      public boolean isInteger()
      Specified by:
      isInteger in interface org.semanticweb.owlapi.model.OWLLiteral
    • isBoolean

      public boolean isBoolean()
      Specified by:
      isBoolean in interface org.semanticweb.owlapi.model.OWLLiteral
    • isDouble

      public boolean isDouble()
      Specified by:
      isDouble in interface org.semanticweb.owlapi.model.OWLLiteral
    • isFloat

      public boolean isFloat()
      Specified by:
      isFloat in interface org.semanticweb.owlapi.model.OWLLiteral
    • parseInteger

      public int parseInteger()
      Specified by:
      parseInteger in interface org.semanticweb.owlapi.model.OWLLiteral
    • parseBoolean

      public boolean parseBoolean()
      Specified by:
      parseBoolean in interface org.semanticweb.owlapi.model.OWLLiteral
    • parseDouble

      public double parseDouble()
      Specified by:
      parseDouble in interface org.semanticweb.owlapi.model.OWLLiteral
    • parseFloat

      public float parseFloat()
      Specified by:
      parseFloat in interface org.semanticweb.owlapi.model.OWLLiteral
    • getSignatureSet

      protected Set<org.semanticweb.owlapi.model.OWLEntity> getSignatureSet()
      Description copied from class: OWLObjectImpl
      Gets the signature of this object. The set is a copy, changes are not reflected back.
      Overrides:
      getSignatureSet in class OWLObjectImpl
      Returns:
      a modifiable sorted Set of entities that represents the signature of this object
    • getDatatypeSet

      protected Set<org.semanticweb.owlapi.model.OWLDatatype> getDatatypeSet()
      Description copied from class: OWLObjectImpl
      Gets the datatypes that are in the signature of this object. The set is a copy, changes are not reflected back.
      Overrides:
      getDatatypeSet in class OWLObjectImpl
      Returns:
      a modifiable sorted Set of the datatypes that are in the signature of this object
    • containsEntityInSignature

      public boolean containsEntityInSignature(@Nullable org.semanticweb.owlapi.model.OWLEntity entity)
      Specified by:
      containsEntityInSignature in interface org.semanticweb.owlapi.model.HasContainsEntityInSignature
      Overrides:
      containsEntityInSignature in class OWLObjectImpl
    • getNamedClassSet

      protected Set<org.semanticweb.owlapi.model.OWLClass> getNamedClassSet()
      Description copied from class: OWLObjectImpl
      Gets the classes in the signature of this object. The returned set is a subset of the signature, and is not backed by the signature; it is a modifiable collection and changes are not reflected by the signature.
      Overrides:
      getNamedClassSet in class OWLObjectImpl
      Returns:
      a modifiable sorted Set containing the classes that are in the signature of this object
    • getNamedIndividualSet

      protected Set<org.semanticweb.owlapi.model.OWLNamedIndividual> getNamedIndividualSet()
      Description copied from class: OWLObjectImpl
      Gets all the individuals that are in the signature of this object. The set is a copy, changes are not reflected back.
      Overrides:
      getNamedIndividualSet in class OWLObjectImpl
      Returns:
      a modifiable sorted Set containing the individuals that are in the signature of this object
    • getDataPropertySet

      protected Set<org.semanticweb.owlapi.model.OWLDataProperty> getDataPropertySet()
      Description copied from class: OWLObjectImpl
      Obtains the data properties that are in the signature of this object. The set is a copy, changes are not reflected back.
      Overrides:
      getDataPropertySet in class OWLObjectImpl
      Returns:
      a modifiable sorted Set of the data properties that are in the signature of this object
    • getObjectPropertySet

      protected Set<org.semanticweb.owlapi.model.OWLObjectProperty> getObjectPropertySet()
      Description copied from class: OWLObjectImpl
      Obtains the (named) object properties that are in the signature of this object. The set is a copy, changes are not reflected back.
      Overrides:
      getObjectPropertySet in class OWLObjectImpl
      Returns:
      a modifiable sorted Set of the object properties that are in the signature of this object
    • getAnnotationPropertySet

      protected Set<org.semanticweb.owlapi.model.OWLAnnotationProperty> getAnnotationPropertySet()
      Description copied from class: OWLObjectImpl
      Obtains the annotation properties that are in the signature of this object. The set is a copy, changes are not reflected back.
      Overrides:
      getAnnotationPropertySet in class OWLObjectImpl
      Returns:
      a modifiable sorted Set of the annotation properties that are in the signature of this object
    • getClassExpressionSet

      protected Set<org.semanticweb.owlapi.model.OWLClassExpression> getClassExpressionSet()
      Description copied from class: OWLObjectImpl
      Gets all the nested (includes top level) class expressions that are used in this object. The set is a copy, changes are not reflected back.
      Overrides:
      getClassExpressionSet in class OWLObjectImpl
      Returns:
      a modifiable unordered Set of OWLClassExpressions that represent the nested class expressions used in this object
    • getAnonymousIndividualSet

      protected Set<org.semanticweb.owlapi.model.OWLAnonymousIndividual> getAnonymousIndividualSet()
      Description copied from class: OWLObjectImpl
      Gets the anonymous individuals occurring in this object. The set is a copy, changes are not reflected back.
      Overrides:
      getAnonymousIndividualSet in class OWLObjectImpl
      Returns:
      a modifiable sorted Set of the anonymous individuals
    • initHashCode

      public int initHashCode()
      Specified by:
      initHashCode in interface org.semanticweb.owlapi.model.OWLLiteral
      Specified by:
      initHashCode in interface org.semanticweb.owlapi.model.OWLObject
    • equals

      public boolean equals(@Nullable Object obj)
      Answers whether some other object is "equal to" this one.

      The comparison is performed by the lexical form, language tag and OWL Datatype. So, "01"^^xsd:integer and "1"^^xsd:integer are two different literals. Also, "1e-07"^^xsd:double and "1.OE7"^^xsd:double are not equal, although the expression literal.getLiteralLabel().getValue() will return equal objects for both literals from the mentioned pairs. Also note: the language tag is a String, and therefore the comparison is case-sensitive, e.g. the tags "SU-su" and "su-su" are not equal.

      Overrides:
      equals in class OWLObjectImpl
      Parameters:
      obj - Object anything
      Returns:
      true if this object is the same as the obj argument; false otherwise