Adding a bit
[apertium.git] / apertium-dictionary-form / config.php
blobbaaf982ba6aee2ed4d552ff9588c5d6643cf12bd
1 <?
2 require_once 'pair.php';
4 class Config {
6 public $wd = '';
7 public $cd = '';
8 public $pairs;
9 public $doc;
11 function Config($_file) {
12 $this->doc = new DOMDocument;
13 $this->doc->load($_file);
14 $this->parse_config();
17 function parse_config() {
18 $working_dir = $this->doc->getElementsByTagName('wd');
19 $cache_dir = $this->doc->getElementsByTagName('cache');
21 $this->wd = $working_dir->item(0)->firstChild->wholeText;
22 $this->cd = $cache_dir->item(0)->firstChild->wholeText . '/';
24 $enabled_pairs = $this->doc->getElementsByTagName('pair');
26 foreach($enabled_pairs as $pair) {
27 $pair_name = $pair->getAttribute('n');
29 $this->pairs[$pair_name] = new Pair($this->wd, $pair_name, $pair);
30 $this->pairs[$pair_name]->cachedir = $this->cd . $pair_name . '/';
32 $enabled_tags = $pair->getElementsByTagName('tag');
34 foreach($enabled_tags as $tag) {
35 $tag_name = $tag->getAttribute('n');
36 $show_list = array();
38 $shows = $tag->getElementsByTagName('show');
40 foreach($shows as $show) {
41 $syms = $show->getAttribute('syms');
42 array_push($show_list, $syms);
45 $sides = $tag->getElementsByTagName('side');
47 foreach($sides as $side) {
48 $paradigm_display_mode = "";
49 $current_side = $side->getAttribute('n');
50 $templates = $side->getElementsByTagName('use-template');
52 foreach($templates as $template) {
53 $tag = $template->getAttribute('tags');
54 $file = $template->getAttribute('file');
55 $this->pairs[$pair_name]->add_template($file, $tag, $current_side);
58 $gloss_sections = $side->getElementsByTagName('paradigms');
60 foreach($gloss_sections as $gloss_section) {
61 $paradigm_display_mode = $gloss_section->getAttribute('display');
62 $glosses = $gloss_section->getElementsByTagName('paradigm');
64 foreach($glosses as $gloss) {
65 $name = $gloss->getAttribute('n');
66 $gloss = $gloss->getAttribute('c');
67 //print $name . ' ~ ' . $gloss . "\n";
68 $this->pairs[$pair_name]->add_gloss($name, $gloss, $current_side);
72 $this->pairs[$pair_name]->set_display_mode($tag_name, $paradigm_display_mode, $current_side);
75 $this->pairs[$pair_name]->add_tag($tag_name, $show_list);
78 $this->pairs[$pair_name]->populate();
82 function pairs() {
83 return $this->pairs;
86 function get_pair($_name) {
87 return $this->pairs[$_name];