Module: TripleParser

Defined in:
lib/triple_parser.rb,
lib/triple_parser/third.rb,
lib/triple_parser/to_rdf.rb,
lib/triple_parser/t_maker.rb,
lib/triple_parser/settings.rb,
lib/triple_parser/splitter.rb,
lib/triple_parser/triple_set.rb,
lib/triple_parser/variable_splitter.rb,
lib/triple_parser/unspecified_splitter.rb,
lib/triple_parser/bracketed_url_splitter.rb,
lib/triple_parser/regional_text_splitter.rb,
lib/triple_parser/colon_separated_splitter.rb

Defined Under Namespace

Modules: Settings Classes: BracketedUrlSplitter, ColonSeparatedSplitter, RegionalTextSplitter, Splitter, TMaker, Third, ToRdf, TripleSet, UnspecifiedSplitter, VariableSplitter

Class Method Summary collapse

Class Method Details

.get_rdf_for(third) ⇒ Object



43
44
45
# File 'lib/triple_parser.rb', line 43

def self.get_rdf_for(third)
  ToRdf.new(third).to_s if third
end

.input(new_input) ⇒ Object



8
9
10
# File 'lib/triple_parser.rb', line 8

def self.input(new_input)
  @input = new_input
end

.to_rdf(input) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/triple_parser.rb', line 31

def self.to_rdf(input)
  @input = input
  output = triples.collect do |t|
    [
      get_rdf_for(t.subject),
      get_rdf_for(t.predicate),
      get_rdf_for(t.object)
    ].join(' ') + " ."
  end 
  return output
end

.triplesObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/triple_parser.rb', line 12

def self.triples
  @triples = Array.new
  case @input.class.to_s
    when 'String'
      @input.each_line do |triple| 
        next if /^\s*$/ =~ triple
        @triples << TripleSet.new(triple)
      end
    when 'Array'
      @input.compact.each do |triple|
        @triples << TripleSet.new(triple)
      end
  else
    raise "Input format not recognised"
  end
  
  return @triples
end