Top Level Namespace

Includes:
Lumix

Defined Under Namespace

Modules: Lumix Classes: AddFulltagged, Categories, ConfigStruct, CreateLookupTables, CreateTables, Pool, String, TaggedText, TextProcessing

Constant Summary collapse

Texts =
{:search => "Searching...", :read => "Importing files", :link => "Linking texts"}
Indicator =
%w'} ) ] | [ ( {'
CONF =
'config.yaml'
CConfig =
YAML.load_file(CONF) rescue ConfigStruct.new('jdbc:postgresql://localhost:5432/concordancer?user=concordancer&password=concordancer')
CORRECTIONS =
<<-TXT
catre | S
fetite | NPRN
in | S
si | C
circa | R
fata de| S
maxima | ASON
inainte| R
in materie de | R
tin | V3
beneficiaza | V3
: | COLON
ocupa | VN
asigurata | VPSF
mine | PPSA
batut | VPSM
insa | C
impotriva | S
americana | ASN
caruia | R
da | VN
duce| VN
primeasca | V3
daca | C
bulgara | ASN
ramina | V3
albaneza | ASN
pina | S
paraseasca | V3
publica | ASN
inceapa | V3
ecologic | ASN
internationala | ASN
ecologista | ASN
cada | V3
linga | S
adevaratele | APRY
citiva | PI
americana | ASN
Miclici| NP
fara | S
cit | PI
sugereaza | V3
incasa | VN
circa | R
ghiceste | V3
tarile |NPRY
araba | ASN
citeva | PI
schimbindu | VG
dupa | S
uleiurilor_vegetale | NPOY
botosaneana | ASN
oricarui | PI
TXT

Constants included from Lumix

Lumix::DB_VERSION, Lumix::RELINK, Lumix::S_BEGIN, Lumix::S_END, Lumix::SearchStrategy, Lumix::TEXT_ID, Lumix::T_BEGIN, Lumix::T_END, Lumix::WORKERS

Instance Method Summary collapse

Methods included from Lumix

#conc, #create_concordancer, #import_files, #link, #reconnect, #relink, #simulate_link, #to_filename

Instance Method Details

#correct(t) ⇒ Object



68
69
70
71
72
# File 'lib/lumix/corrections.rb', line 68

def correct(t)
  corrections.inject(t) do |result, (re, sub)|
    result.gsub(re, sub)
  end
end

#correct_all(path) ⇒ Object



74
75
76
77
78
79
80
# File 'lib/lumix/corrections.rb', line 74

def correct_all(path)
  fs = Dir.glob(File.join(path, '*tagged*'))
  fs.each do |fn|
    t = correct(File.read(fn))
    File.open(fn, 'w') { |f| f.print t }
  end
end

#correctionsObject



60
61
62
63
64
65
66
# File 'lib/lumix/corrections.rb', line 60

def corrections
  @corrections ||= CORRECTIONS.split(/\n/).map do |line|
    word, tag = line.split(/\|/).map(&:strip)
    puts "Tagging #{word} as #{tag}"
    [/\b#{word}\|\S+/, "#{word}\|#{tag}"]
  end
end

#create_findings_file(filter, filename = to_filename(filter), &block) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/lumix/cli.rb', line 33

def create_findings_file(filter, filename = to_filename(filter), &block)
  if File.exists?(filename)
    puts "File #{filename} already exists! Ignoring."
  else
    File.open(filename, 'w', &block)
  end
end

#helpObject



5
6
7
8
9
10
# File 'lib/lumix/cli.rb', line 5

def help
  puts "lumix-cli import <en|ro> <path>"
  puts "lumix-cli [search] 'search string' ..."
  puts "lumix-cli relink"
  exit
end

#import!(lang, *files) ⇒ Object



46
47
48
49
# File 'lib/lumix/cli.rb', line 46

def import!(lang, *files)
  conc.link_on_import!
  import_files(lang, *files)
end

#save!Object



14
15
16
17
18
# File 'lib/lumix/gui.rb', line 14

def save!
  File.open(CONF, 'w') do |f|
    f.write(CConfig.to_yaml)
  end
end

#search(*filters) ⇒ Object



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

def search(*filters)
  files = []
  fs = filters.map do |filt|
    file = create_findings_file(filt)
    next unless file
    files << file
    conc.create_filter(filt) do |text, tagged|
      file.puts "#{text.name}: #{text.left} | #{tagged.to_s} | #{text.right}"
      #file.puts "#{text.name}: #{tagged.to_s}"
    end
  end.compact

  conc.find(fs) unless fs.empty?

  fs.each do |f|
    puts "Found #{f.results == 0 ? 'no' : f.results} matches for #{f.filter}"
  end
ensure
  files.each{ |f| f.close }
end

#tag(lang, *files) ⇒ Object



41
42
43
44
# File 'lib/lumix/cli.rb', line 41

def tag(lang, file)
  conc.tp.lang = lang
  puts conc.tp.process(File.read(file))
end