All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.clerezza.scala.utils.EzLiteral.scala Maven / Gradle / Ivy

The newest version!
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor  license  agreements.  See the NOTICE file distributed
 * with this work  for  additional  information  regarding  copyright
 * ownership.  The ASF  licenses  this file to you under  the  Apache
 * License, Version 2.0 (the "License"); you may not  use  this  file
 * except in compliance with the License.  You may obtain  a copy  of
 * the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless  required  by  applicable law  or  agreed  to  in  writing,
 * software  distributed  under  the  License  is  distributed  on an
 * "AS IS"  BASIS,  WITHOUT  WARRANTIES  OR  CONDITIONS  OF ANY KIND,
 * either  express  or implied.  See  the License  for  the  specific
 * language governing permissions and limitations under  the License.
 */
package org.apache.clerezza.scala.utils

import org.apache.clerezza.{IRI, Language, Literal}
import org.apache.clerezza.implementation.literal._
import org.apache.clerezza.implementation.literal.{PlainLiteralImpl, TypedLiteralImpl}
import org.apache.clerezza.ontologies.XSD

object EzLiteral extends EzLiteralImplicits

trait EzLiteralImplicits {

    implicit def string2lit(str: String) = new EzLiteral(str)

}

/**
  * An EzLiteral is a typed string literal - ie, just a String literal - that comes with N3/turtle like methods
  * to map to other types of literals.
  *
  * This makes it useful when combined with the EzLiteralImplicit for writing out literals
  *
  * 
  * "ABCDEFGHIJKLMN"                   -- a plain string converted to a EzLiteral
  * "some text in english".lang(en)    -- an english literal
  * "1234"^^XSD.int                    -- a number
  * 
  *
  * @author bblfish
  */
class EzLiteral(string: String) extends TypedLiteralImpl(string, XSD.string) {

    /**
      * @return a plain literal with language specified by lang
      */
    def lang(lng: String): Literal = lang(new Language(lng))

    /**
      * @return a plain literal with language specified by lang
      */
    def lang(lng: Language): Literal = new PlainLiteralImpl(string, lng)

    /**
      * Map to a Typed Literal of given type
      */
    def ^^(typ: IRI): Literal = new TypedLiteralImpl(string, typ)

    /**
      * alias for iri
      */
    @deprecated(message = "use  `iri`", since = "1.0.0")
    def uri = iri

    /**
      * Map to an IRI of given lexical form
      */
    def iri = new IRI(string)

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy