Module: RTM::IO::TmapiXFrom::TopicMap

Defined in:
lib/rtm/io/tmapix_from.rb

Instance Method Summary collapse

Instance Method Details

#from_anything(reader_class, *args) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/rtm/io/tmapix_from.rb', line 12

def from_anything(reader_class, *args)
  raise "Only supported for TMAPI backends!!" unless self.kind_of?(Java::OrgTmapiCore::TopicMap) || self.kind_of?(Java::OrgTmapiCore::TopicMapSystem)

  params = {}
  # See if we got a params hash. It must be at the end, if it is given.
  # Take it off, so it won't be unshifted later.
  params = args.pop if args.last.is_a?(Hash)

  # Take the source as next (i.e. second after the writer) positional parameter or from hash.
  # Leave nil if neither found.
  source = args.shift || params[:source]

  # Take the base_iri as next (i.e. third after the file) positional parameter or from the hash.
  # Use the topic maps's base_iri if neither found.
  base_iri = args.shift || params[:base_iri]
  unless base_iri
    if self.kind_of?(RTM::TopicMap)
      base_iri = self.base_iri
    else
      base_iri = "imported:FIXME"
    end
  end

  if self.kind_of?(RTM::TopicMap)
    topic_map = self
  else
    topic_map = create(base_iri)
  end

  reader_class.new(topic_map, java.io.File.new(source)).read
  topic_map
end

#from_ctm(*args) ⇒ Object

Reads a Topic Map from an CTM File whose location is given as String parameter.

:call-seq:

from_ctm(filename)


61
62
63
# File 'lib/rtm/io/tmapix_from.rb', line 61

def from_ctm(*args)
  from_anything(org.tmapix.io.CTMTopicMapReader, *args)
end

#from_jtm(*args) ⇒ Object

Reads a JSON Topic Maps (JTM) File whose location is given as String parameter.

:call-seq:

from_jtm(filename)


71
72
73
74
# File 'lib/rtm/io/tmapix_from.rb', line 71

def from_jtm(*args)
  # seems not to acceped all files that are found to be valid by the JTM validator
  from_anything(org.tmapix.io.JTMTopicMapReader, *args)
end

#from_ltm(*args) ⇒ Object

Reads a Topic Map from an LTM File whose location is given as String parameter.

:call-seq:

from_ltm(filename)


51
52
53
# File 'lib/rtm/io/tmapix_from.rb', line 51

def from_ltm(*args)
  from_anything(org.tmapix.io.LTMTopicMapReader, *args)
end

#from_n3(filename, vocab) ⇒ Object

Reads a Notation3 (N3) File whose location is given as String . The source vocabulary must provide the mapping vocabulary. The syntax of the vocabulary is guessed.

:call-seq:

from_n3(filename, source vocabulary)


129
130
131
132
133
134
# File 'lib/rtm/io/tmapix_from.rb', line 129

def from_n3(filename, vocab)
  raise "Only supported for TMAPI backends!!" unless self.kind_of? Java::OrgTmapiCore::TopicMap
  reader = org.tmapix.io.N3TopicMapReader.new self,  java.io.File.new(filename)
  reader.setMappingSource(java.io.File.new(vocab))
  reader.read
end

#from_rdfxml(filename, vocab) ⇒ Object

Reads a RDF/XML File whose location is given as String The source vocabulary must provide the mapping vocabulary. The syntax of the vocabulary is guessed.

:call-seq:

from_rdfxml(filename, source vocabulary)


145
146
147
148
149
150
# File 'lib/rtm/io/tmapix_from.rb', line 145

def from_rdfxml(filename, vocab)
  raise "Only supported for TMAPI backends!!" unless self.kind_of? Java::OrgTmapiCore::TopicMap
  reader = org.tmapix.io.RDFXMLTopicMapReader.new self,  java.io.File.new(filename)
  reader.setMappingSource(java.io.File.new(vocab))
  reader.read
end

#from_tmxml(*args) ⇒ Object

Reads a Friendly Topic Maps XML (TM/XML) File independent of the version whose location is given as String parameter.

:call-seq:

from_tmxml(filename)


83
84
85
# File 'lib/rtm/io/tmapix_from.rb', line 83

def from_tmxml(*args)
  from_anything(org.tmapix.io.TMXMLTopicMapReader, *args)
end

#from_xtm(*args) ⇒ Object

Reads a XML Topic Maps (XTM) File independent of the version whose location is given as String parameter.

:call-seq:

from_xtm(filename)


116
117
118
# File 'lib/rtm/io/tmapix_from.rb', line 116

def from_xtm(*args)
  from_anything(org.tmapix.io.XTMTopicMapReader, *args)
end

#from_xtm10(*args) ⇒ Object Also known as: from_xtm1

Reads a XML Topic Maps (XTM) 1.0 File whose location is given as String parameter.

:call-seq:

from_xtm10(filename)


93
94
95
# File 'lib/rtm/io/tmapix_from.rb', line 93

def from_xtm10(*args)
  from_anything(org.tmapix.io.XTM10TopicMapReader, *args)
end

#from_xtm20(*args) ⇒ Object Also known as: from_xtm2

Reads a XML Topic Maps (XTM) 2.0 File whose location is given as String parameter.

:call-seq:

from_xtm20(filename)


104
105
106
# File 'lib/rtm/io/tmapix_from.rb', line 104

def from_xtm20(*args)
  from_xtm(*args)
end