1 /*************************************************************************/
2 /* Copyright (c) 2004                                                    */
3 /* Daniel Sleator, David Temperley, and John Lafferty                    */
4 /* Copyright 2008, 2009, 2013, 2014 Linas Vepstas                        */
5 /* All rights reserved                                                   */
6 /*                                                                       */
7 /* Use of the link grammar parsing system is subject to the terms of the */
8 /* license set forth in the LICENSE file included with this software.    */
9 /* This license allows free redistribution and use in source and binary  */
10 /* forms, with or without modification, subject to certain conditions.   */
11 /*                                                                       */
12 /*************************************************************************/
13 
14 #include "api-structures.h"
15 #include "linkage.h"
16 #include "post-process/post-process.h" // for linkage_free_pp_info
17 #include "utilities.h"
18 
free_linkage(Linkage linkage)19 void free_linkage(Linkage linkage)
20 {
21 	exfree((void *) linkage->word, sizeof(const char *) * linkage->num_words);
22 	exfree(linkage->chosen_disjuncts, linkage->num_words * sizeof(Disjunct *));
23 	free(linkage->link_array);
24 
25 	free(linkage->disjunct_list_str);
26 
27 	linkage_free_pp_domains(linkage);
28 
29 	/* XXX FIXME */
30 	free(linkage->wg_path);
31 	free(linkage->wg_path_display);
32 }
33 
free_linkages(Sentence sent)34 void free_linkages(Sentence sent)
35 {
36 	size_t in;
37 	Linkage lkgs = sent->lnkages;
38 	if (!lkgs) return;
39 
40 	for (in=0; in<sent->num_linkages_alloced; in++)
41 	{
42 		free_linkage(&lkgs[in]);
43 	}
44 
45 	free(lkgs);
46 	sent->num_linkages_alloced = 0;
47 	sent->num_linkages_found = 0;
48 	sent->num_linkages_post_processed = 0;
49 	sent->num_valid_linkages = 0;
50 	sent->lnkages = NULL;
51 }
52 
53 /* Partial, but not full initialization of the linkage struct ... */
partial_init_linkage(Sentence sent,Linkage lkg,unsigned int N_words)54 void partial_init_linkage(Sentence sent, Linkage lkg, unsigned int N_words)
55 {
56 	lkg->num_links = 0;
57 	lkg->lasz = 2 * N_words;
58 	lkg->link_array = (Link *) malloc(lkg->lasz * sizeof(Link));
59 	memset(lkg->link_array, 0, lkg->lasz * sizeof(Link));
60 
61 	lkg->num_words = N_words;
62 	lkg->cdsz =  N_words;
63 	lkg->chosen_disjuncts = (Disjunct **) exalloc(lkg->cdsz * sizeof(Disjunct *));
64 	memset(lkg->chosen_disjuncts, 0, N_words * sizeof(Disjunct *));
65 
66 	lkg->disjunct_list_str = NULL;
67 	lkg->pp_domains = NULL;
68 	lkg->sent = sent;
69 }
70