source: src/dgp/main.cc @ d6a59ca

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

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

  • Property mode set to 100644
File size: 3.8 KB
RevLine 
[5f4d9c3]1
2/**
3 * Package:     UAM Text Tools
4 * Component:   dgp (dg parser)
5 * Version:     1.0
6 * Author:      Tomasz Obrebski
7 */
8
[a15e59b]9#include <ctime>
10#include <sys/time.h>
11
[5f4d9c3]12#include "global.hh"
13#include "mgraph.hh"
14#include "sgraph.hh"
15#include "grammar.hh"
[e7de6cc]16#include "dgp1.hh"
[5f4d9c3]17#include "../common/common.h"
18#include "cmdline.h"
19
20#define MAXSEGMENTS 500
21
[a15e59b]22#define MICROSECONDSELAPSED(A,B) ((B.tv_sec - A.tv_sec)*1000000 + (B.tv_usec - A.tv_usec))
23
[5f4d9c3]24char segment[MAXSEGMENTS][MAXLINE];
25int segcount=0;
26char seg_mnode[MAXSEGMENTS];
27char grammarfile[255];
28
29
30Grammar grammar;
31MGraph mgraph;
[e7de6cc]32SGraph sgraph(mgraph);
[5f4d9c3]33
34FILE* grammarf;
35FILE* debugf=stdout;
36unsigned int info=0U;
37
[a15e59b]38bool printtimeinfo=false;
39
[3b02b04]40
[5f4d9c3]41void output();
42
43main(int argc, char* argv[])
44{
45  gengetopt_args_info args;
[3b02b04]46  struct timeval readgrammar_starttime,readgrammar_endtime;
[5f4d9c3]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
[a15e59b]64  if(args.time_given) printtimeinfo=true;
65
[5f4d9c3]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
[3b02b04]75  gettimeofday(&readgrammar_starttime,NULL);
76
[5f4d9c3]77  grammar.read(grammarf);
78  fclose(grammarf);
79
[3b02b04]80  gettimeofday(&readgrammar_endtime,NULL);
[e7de6cc]81
[3b02b04]82  if(printtimeinfo)
83    fprintf(stderr,"### START  TIME: %10.2fms\n", (float)MICROSECONDSELAPSED(readgrammar_starttime,readgrammar_endtime)/1000 );
[e7de6cc]84
[3b02b04]85////////////////////////////////////////////////////////////////////////////////////////////////////
86// TESTOWANIE POPRAWNOŠCI ODCZYTU GRAMATYKI
[e7de6cc]87  // grammar.write(cout);
88  // exit(0);
[3b02b04]89////////////////////////////////////////////////////////////////////////////////////////////////////
[e7de6cc]90
[a15e59b]91  struct timeval starttime,afterinput,afterparse,endtime;
[e7de6cc]92
[5f4d9c3]93  mgraph.clear();
94  sgraph.clear();
95
96  char line[1000];
97  while (fgets(line, MAXLINE+1, inputf))
98  {
[a15e59b]99    gettimeofday(&starttime,NULL);
[5f4d9c3]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    {
[a15e59b]112      gettimeofday(&afterinput,NULL);
[3b02b04]113     
[e7de6cc]114      dgp1(); // parametry!!! MGraph, SGraph, Grammar
[3b02b04]115
[a15e59b]116      gettimeofday(&afterparse,NULL);
[5f4d9c3]117      output();
[a15e59b]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        }
[5f4d9c3]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    {
[e7de6cc]147      MNode& m=mgraph[seg_mnode[si]];
[5f4d9c3]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.