source: app/src/dgp/main.cc @ 0214596

help
Last change on this file since 0214596 was 0214596, checked in by pawelk <pawelk@…>, 16 years ago

Dodalismy do pakietu utt komponent dgp (brak configow i innych bajerow).

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

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