source: app/src/dgp/main.cc @ 9b57c4d

help
Last change on this file since 9b57c4d was df77b87, checked in by obrebski <obrebski@…>, 17 years ago

w struktura.txt wpisalem sugestie R.D.
dgp obsluguje configa

git-svn-id: svn://atos.wmid.amu.edu.pl/utt@37 e293616e-ec6a-49c2-aa92-f4a8b91c5d16

  • Property mode set to 100644
File size: 2.6 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 "dgp0.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];
22
23Grammar grammar;
24MGraph mgraph;
25SGraph sgraph;
26
27FILE* grammarf;
28FILE* debugf=stdout;
29unsigned int info=0U;
30
31void output();
32
33main(int argc, char* argv[])
34{
35  gengetopt_args_info args;
36
37  if(cmdline_parser(argc,argv,&args) != 0)
38    exit(1);
39
40  process_config_files(&args,argv[0]);
41  process_common_options(&args,argv[0]);
42
43//   if(args.help_given) cmdline_parser_print_help ();
44
45//   if(args.input_given)
46//     if(!(inputf=fopen(args.input_arg,"r")))
47//       fprintf(stderr,"dgp: input file not found: %s.\n", args.input_arg), exit(1);
48
49//   if(args.output_given)
50//     if(!(outputf=fopen(args.output_arg,"w")))
51//       fprintf(stderr,"dgp: cannot open output file: %s.\n", args.output_arg), exit(1);
52
53  if(!(grammarf=fopen(args.grammar_arg,"r")))
54    fprintf(stderr,"dgp: grammar file not found: %s.\n", args.grammar_arg), exit(1);
55
56  if(args.debug_given) debug=true;
57
58  for(char* c=args.info_arg; *c!='\0' ; ++c)
59    switch(*c)
60    {
61    case 'h': info|=SGraph::HEADS; break;
62    case 'd': info|=SGraph::DEPS; break;
63    case 's': info|=SGraph::SETS; break;
64    case 'c': info|=SGraph::CONSTRAINTS; break;
65    }
66
67  grammar.read(grammarf);
68  fclose(grammarf);
69
70  mgraph.clear();
71  sgraph.clear();
72
73  char line[1000];
74  while (fgets(line, MAXLINE+1, inputf))
75  {
76    line[strlen(line)-1] = '\0';
77    strcpy(segment[segcount],line);
78
79    char segtype[80];
80
81    seg_mnode[segcount] = process_seg(line, args) ? mgraph.add_node(line) : -1;
82
83    segcount++;
84
85    getfield(line,"3",segtype);
86    if(strcmp(segtype,"EOS")==0)
87    {
88      dgp0(); // parametry!!! MGraph, SGraph, Grammar
89      output();
90     
91      mgraph.clear();
92      sgraph.clear();
93      segcount=0;
94    }
95    //    if(args.interactive_flag) { fflush(outputf); fflush(failedf); }
96  }
97 
98  fclose(inputf);
99  fclose(outputf);
100  cmdline_parser_free(&args);
101  exit(0);
102}
103
104void output()
105{
106  for(int si=0; si<segcount; ++si)
107  {
108    if(seg_mnode[si]>=0)
109    {
110      MNode& m=mgraph.nodes[seg_mnode[si]];
111      for(vector<int>::iterator s=m.snodes.begin(); s!=m.snodes.end(); ++s)
112      {
113        fputs(segment[si],outputf);
114        sgraph.print_node(outputf, *s, info);
115        fputc('\n',outputf);
116      }
117    }
118    else
119    {
120      fputs(segment[si],outputf);
121      fputc('\n',outputf);
122    }
123  }
124}
Note: See TracBrowser for help on using the repository browser.