source: src/dgp/main.cc @ 854bece

Last change on this file since 854bece was 3b02b04, checked in by Tomasz Obrebski <to@…>, 11 years ago

prawie ca�kiem nowe dgc, du�e zmiany w dgp, pomniejsze poprawki

  • Property mode set to 100644
File size: 3.8 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 <ctime>
10#include <sys/time.h>
11
12#include "global.hh"
13#include "mgraph.hh"
14#include "sgraph.hh"
15#include "grammar.hh"
16#include "dgp1.hh"
17#include "../common/common.h"
18#include "cmdline.h"
19
20#define MAXSEGMENTS 500
21
22#define MICROSECONDSELAPSED(A,B) ((B.tv_sec - A.tv_sec)*1000000 + (B.tv_usec - A.tv_usec))
23
24char segment[MAXSEGMENTS][MAXLINE];
25int segcount=0;
26char seg_mnode[MAXSEGMENTS];
27char grammarfile[255];
28
29
30Grammar grammar;
31MGraph mgraph;
32SGraph sgraph(mgraph);
33
34FILE* grammarf;
35FILE* debugf=stdout;
36unsigned int info=0U;
37
38bool printtimeinfo=false;
39
40
41void output();
42
43main(int argc, char* argv[])
44{
45  gengetopt_args_info args;
46  struct timeval readgrammar_starttime,readgrammar_endtime;
47
48  if(cmdline_parser(argc,argv,&args) != 0)
49    exit(1);
50
51  process_config_files(&args,argv[0]);
52  process_common_options(&args,argv[0]);
53
54  if(!args.grammar_given)
55    fprintf(stderr,"dgp: no grammar given\n");
56
57  expand_path(args.grammar_arg,grammarfile);
58
59  if(!(grammarf=fopen(grammarfile,"r")))
60    fprintf(stderr,"dgp: grammar file not found: %s.\n", grammarfile), exit(1);
61
62  if(args.debug_given) debug=true;
63
64  if(args.time_given) printtimeinfo=true;
65
66  for(char* c=args.info_arg; *c!='\0' ; ++c)
67    switch(*c)
68    {
69    case 'h': info|=SGraph::HEADS; break;
70    case 'd': info|=SGraph::DEPS; break;
71    case 's': info|=SGraph::SETS; break;
72    case 'c': info|=SGraph::CONSTRAINTS; break;
73    }
74
75  gettimeofday(&readgrammar_starttime,NULL);
76
77  grammar.read(grammarf);
78  fclose(grammarf);
79
80  gettimeofday(&readgrammar_endtime,NULL);
81
82  if(printtimeinfo)
83    fprintf(stderr,"### START  TIME: %10.2fms\n", (float)MICROSECONDSELAPSED(readgrammar_starttime,readgrammar_endtime)/1000 );
84
85////////////////////////////////////////////////////////////////////////////////////////////////////
86// TESTOWANIE POPRAWNOŠCI ODCZYTU GRAMATYKI
87  // grammar.write(cout);
88  // exit(0);
89////////////////////////////////////////////////////////////////////////////////////////////////////
90
91  struct timeval starttime,afterinput,afterparse,endtime;
92
93  mgraph.clear();
94  sgraph.clear();
95
96  char line[1000];
97  while (fgets(line, MAXLINE+1, inputf))
98  {
99    gettimeofday(&starttime,NULL);
100    line[strlen(line)-1] = '\0';
101    strcpy(segment[segcount],line);
102
103    char segtype[80];
104
105    seg_mnode[segcount] = process_seg(line, args) ? mgraph.add_node(line) : -1;
106
107    segcount++;
108
109    getfield(line,"3",segtype);
110    if(strcmp(segtype,"EOS")==0)
111    {
112      gettimeofday(&afterinput,NULL);
113     
114      dgp1(); // parametry!!! MGraph, SGraph, Grammar
115
116      gettimeofday(&afterparse,NULL);
117      output();
118      gettimeofday(&endtime,NULL);
119
120      if(printtimeinfo)
121        {
122          fprintf(stderr,"### INPUT  TIME: %10.2fms\n", (float)MICROSECONDSELAPSED(starttime,afterinput)/1000 );
123          fprintf(stderr,"### PARSE  TIME: %10.2fms\n", (float)MICROSECONDSELAPSED(afterinput,afterparse)/1000 );
124          fprintf(stderr,"### OUTPUT TIME: %10.2fms\n", (float)MICROSECONDSELAPSED(afterparse,endtime)/1000 );
125          fprintf(stderr,"### TOTAL  TIME: %10.2fms\n", (float)MICROSECONDSELAPSED(starttime,endtime)/1000 );
126        }
127     
128      mgraph.clear();
129      sgraph.clear();
130      segcount=0;
131    }
132    //    if(args.interactive_flag) { fflush(outputf); fflush(failedf); }
133  }
134 
135  fclose(inputf);
136  fclose(outputf);
137  cmdline_parser_free(&args);
138  exit(0);
139}
140
141void output()
142{
143  for(int si=0; si<segcount; ++si)
144  {
145    if(seg_mnode[si]>=0)
146    {
147      MNode& m=mgraph[seg_mnode[si]];
148      for(vector<int>::iterator s=m.snodes.begin(); s!=m.snodes.end(); ++s)
149      {
150        fputs(segment[si],outputf);
151        sgraph.print_node(outputf, *s, info);
152        fputc('\n',outputf);
153      }
154    }
155    else
156    {
157      fputs(segment[si],outputf);
158      fputc('\n',outputf);
159    }
160  }
161}
Note: See TracBrowser for help on using the repository browser.