Class JavaNameGenerator

java.lang.Object
cz.cvut.kbss.jopa.owl2java.JavaNameGenerator

public class JavaNameGenerator extends Object
Generates Java names based on IRI identifiers.
  • Constructor Details

    • JavaNameGenerator

      public JavaNameGenerator(PrefixMap prefixMap)
  • Method Details

    • generateJavaNameForIri

      public String generateJavaNameForIri(org.semanticweb.owlapi.model.IRI iri)
      Returns a valid Java identifier extracted from the specified IRI.

      If the IRI contains a non-empty fragment, it is used. Otherwise, the part after the last slash is used as the name.

      Parameters:
      iri - IRI to extract name from
      Returns:
      Java name based on the specified IRI
    • generatePrefixedJavaNameForIri

      public String generatePrefixedJavaNameForIri(org.semanticweb.owlapi.model.IRI iri, org.semanticweb.owlapi.model.OWLOntologyID ontologyId)
      Returns a valid Java identifier extracted from the specified IRI, prefixed with prefix registered for the specified ontology IRI (if available).

      If the IRI contains a non-empty fragment, it is used. Otherwise, the part after the last slash is used as the name.

      If the ontology is anonymous, no prefix is added to the extracted name. If no prefix is registered for the ontology, a prefix represented by extracting a java name from the ontology IRI is used.

      Parameters:
      iri - IRI to extract name from
      ontologyId - Ontology identifier
      Returns:
      Java name based on the specified IRI
    • getOntologyPrefix

      public Optional<String> getOntologyPrefix(org.semanticweb.owlapi.model.IRI ontologyIri)
      Gets the prefix registered for an ontology with the specified identifier.
      Parameters:
      ontologyIri - Ontology IRI
      Returns:
      Optional ontology prefix
    • hasPrefix

      public boolean hasPrefix(org.semanticweb.owlapi.model.IRI ontologyIri)
      Checks whether a prefix exists for the specified ontology identifier.
      Parameters:
      ontologyIri - Ontology IRI
      Returns:
      true if a prefix has been resolved for ontology IRI, false otherwise
    • makeNameValidJava

      public static String makeNameValidJava(String name)
      Returns the specified name sanitized for Java.

      This means the result of this function can be used as/in a Java variable/field/class name.

      Parameters:
      name - The name to sanitize
      Returns:
      Valid Java identifier
    • toCamelCaseNotation

      public static String toCamelCaseNotation(String name)
      Converts the specified name to the Java camel case notation.

      This process removes underscores used to generate the name.

      Parameters:
      name - Generated name
      Returns:
      Converted camel case name