source: src/dgp/main.cc @ abd28d1

Last change on this file since abd28d1 was e7de6cc, checked in by Tomasz Obrebski <to@…>, 12 years ago

new version of dgp
added dgc, tre and compdic components
compiledic renamed to compdic_utf8
./configure updated

  • Property mode set to 100644
File size: 2.4 KB
Line 
1
2/**
3 * Package:     UAM Text Tools
4 * Component:   dgp (dg parser)
5 * Version:     1.0
6 * Author:      Tomasz Obrebski
7 */
8
9#include "global.hh"
10#include "mgraph.hh"
11#include "sgraph.hh"
12#include "grammar.hh"
13#include "dgp1.hh"
14#include "../common/common.h"
15#include "cmdline.h"
16
17#define MAXSEGMENTS 500
18
19char segment[MAXSEGMENTS][MAXLINE];
20int segcount=0;
21char seg_mnode[MAXSEGMENTS];
22char grammarfile[255];
23
24
25Grammar grammar;
26MGraph mgraph;
27SGraph sgraph(mgraph);
28
29FILE* grammarf;
30FILE* debugf=stdout;
31unsigned int info=0U;
32
33void output();
34
35main(int argc, char* argv[])
36{
37  gengetopt_args_info args;
38
39  if(cmdline_parser(argc,argv,&args) != 0)
40    exit(1);
41
42  process_config_files(&args,argv[0]);
43  process_common_options(&args,argv[0]);
44
45  if(!args.grammar_given)
46    fprintf(stderr,"dgp: no grammar given\n");
47
48  expand_path(args.grammar_arg,grammarfile);
49
50  if(!(grammarf=fopen(grammarfile,"r")))
51    fprintf(stderr,"dgp: grammar file not found: %s.\n", grammarfile), exit(1);
52
53  if(args.debug_given) debug=true;
54
55  for(char* c=args.info_arg; *c!='\0' ; ++c)
56    switch(*c)
57    {
58    case 'h': info|=SGraph::HEADS; break;
59    case 'd': info|=SGraph::DEPS; break;
60    case 's': info|=SGraph::SETS; break;
61    case 'c': info|=SGraph::CONSTRAINTS; break;
62    }
63
64  grammar.read(grammarf);
65  fclose(grammarf);
66
67
68
69  // grammar.write(cout);
70  // exit(0);
71
72
73
74  mgraph.clear();
75  sgraph.clear();
76
77  char line[1000];
78  while (fgets(line, MAXLINE+1, inputf))
79  {
80    line[strlen(line)-1] = '\0';
81    strcpy(segment[segcount],line);
82
83    char segtype[80];
84
85    seg_mnode[segcount] = process_seg(line, args) ? mgraph.add_node(line) : -1;
86
87    segcount++;
88
89    getfield(line,"3",segtype);
90    if(strcmp(segtype,"EOS")==0)
91    {
92      dgp1(); // parametry!!! MGraph, SGraph, Grammar
93      output();
94     
95      mgraph.clear();
96      sgraph.clear();
97      segcount=0;
98    }
99    //    if(args.interactive_flag) { fflush(outputf); fflush(failedf); }
100  }
101 
102  fclose(inputf);
103  fclose(outputf);
104  cmdline_parser_free(&args);
105  exit(0);
106}
107
108void output()
109{
110  for(int si=0; si<segcount; ++si)
111  {
112    if(seg_mnode[si]>=0)
113    {
114      MNode& m=mgraph[seg_mnode[si]];
115      for(vector<int>::iterator s=m.snodes.begin(); s!=m.snodes.end(); ++s)
116      {
117        fputs(segment[si],outputf);
118        sgraph.print_node(outputf, *s, info);
119        fputc('\n',outputf);
120      }
121    }
122    else
123    {
124      fputs(segment[si],outputf);
125      fputc('\n',outputf);
126    }
127  }
128}
Note: See TracBrowser for help on using the repository browser.