source: app/src/dgp/main.cc @ 3748bd1

help
Last change on this file since 3748bd1 was 3748bd1, checked in by obrebski <obrebski@…>, 16 years ago

1) dgp nie wysypuje sie na nieznanych kategoriach
2) dodane i uzupelnione konfigi

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

  • Property mode set to 100644
File size: 2.3 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];
22char grammarfile[255];
23
24
25Grammar grammar;
26MGraph mgraph;
27SGraph sgraph;
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  mgraph.clear();
68  sgraph.clear();
69
70  char line[1000];
71  while (fgets(line, MAXLINE+1, inputf))
72  {
73    line[strlen(line)-1] = '\0';
74    strcpy(segment[segcount],line);
75
76    char segtype[80];
77
78    seg_mnode[segcount] = process_seg(line, args) ? mgraph.add_node(line) : -1;
79
80    segcount++;
81
82    getfield(line,"3",segtype);
83    if(strcmp(segtype,"EOS")==0)
84    {
85      dgp0(); // parametry!!! MGraph, SGraph, Grammar
86      output();
87     
88      mgraph.clear();
89      sgraph.clear();
90      segcount=0;
91    }
92    //    if(args.interactive_flag) { fflush(outputf); fflush(failedf); }
93  }
94 
95  fclose(inputf);
96  fclose(outputf);
97  cmdline_parser_free(&args);
98  exit(0);
99}
100
101void output()
102{
103  for(int si=0; si<segcount; ++si)
104  {
105    if(seg_mnode[si]>=0)
106    {
107      MNode& m=mgraph.nodes[seg_mnode[si]];
108      for(vector<int>::iterator s=m.snodes.begin(); s!=m.snodes.end(); ++s)
109      {
110        fputs(segment[si],outputf);
111        sgraph.print_node(outputf, *s, info);
112        fputc('\n',outputf);
113      }
114    }
115    else
116    {
117      fputs(segment[si],outputf);
118      fputc('\n',outputf);
119    }
120  }
121}
Note: See TracBrowser for help on using the repository browser.