Class: OntologyUnited::Serializer::OWL::Manchester

Inherits:
SerializerBase show all
Defined in:
lib/ontology-united/serializer/owl/manchester.rb

Instance Method Summary collapse

Methods inherited from SerializerBase

#class?, #initialize, #join, #mark!, #ontology?, #process, #sentence?, #unmark!

Methods included from OntologyUnited::Stack

#current, #parent, #stack

Constructor Details

This class inherits a constructor from OntologyUnited::Serializer::SerializerBase

Instance Method Details

#class_definition?(ontology_class) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
50
51
52
53
54
# File 'lib/ontology-united/serializer/owl/manchester.rb', line 47

def class_definition?(ontology_class)
  # if no parent is set
  parent.nil? ||
    # or the parent is an ontology itself
    ontology?(parent) ||
    # or it is the first symbol of a sentence
    sentence?(parent) && parent.sentence.first == ontology_class
end

#serialize_class(ontology_class) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/ontology-united/serializer/owl/manchester.rb', line 27

def serialize_class(ontology_class)
  process ontology_class do
    prefix = ontology_class.prefix
    if prefix
      print_name = prefix.apply(ontology_class)
    else
      print_name = "<#{ontology_class.name}>"
    end
    "#{'Class: ' if class_definition?(ontology_class)}#{print_name}"
  end
end

#serialize_import(ontology_import) ⇒ Object



21
22
23
24
25
# File 'lib/ontology-united/serializer/owl/manchester.rb', line 21

def serialize_import(ontology_import)
  process ontology_import do
    "Import: <#{ontology_import.iri || ontology_import.ontology.iri}>"
  end
end

#serialize_ontology(ontology) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/ontology-united/serializer/owl/manchester.rb', line 5

def serialize_ontology(ontology)
  process ontology do
    str = "Ontology: <#{ontology.iri}>\n"
    str << join(ontology.elements, "\n") do |element|
      element.to_s(serializer: self)
    end
  end
end

#serialize_prefix(ontology_prefix) ⇒ Object



14
15
16
17
18
19
# File 'lib/ontology-united/serializer/owl/manchester.rb', line 14

def serialize_prefix(ontology_prefix)
  process ontology_prefix do
    "Prefix: #{ontology_prefix.prefix}: " <<
      "<#{ontology_prefix.iri || ontology_prefix.ontology.iri}#>"
  end
end

#serialize_sentence(ontology_sentence) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/ontology-united/serializer/owl/manchester.rb', line 39

def serialize_sentence(ontology_sentence)
  opts = {serializer: self}
  process ontology_sentence do
    first_class, middle, second_class = ontology_sentence.sentence
    "#{first_class.to_s(opts)} #{middle} #{second_class.to_s(opts)}"
  end
end