<commit_before>/*************************************************************************/
/* Copyright (c) 2004                                                    */
/* <NAME>, <NAME>, and <NAME>                    */
/* All rights reserved                                                   */
/*                                                                       */
/* Use of the link grammar parsing system is subject to the terms of the */
/* license set forth in the LICENSE file included with this software,    */ 
/* and also available at http://www.link.cs.cmu.edu/link/license.html    */
/* This license allows free redistribution and use in source and binary  */
/* forms, with or without modification, subject to certain conditions.   */
/*                                                                       */
/*************************************************************************/


#include <stdarg.h>
#include <link-grammar/api.h>
#include "corpus/corpus.h"

const char * trailer(int mode);
const char * header(int mode);

static void set_centers(Linkage linkage, int center[], int print_word_0, int N_words_to_print)
{
	int i, len, tot;
	tot = 0;
	if (print_word_0) i=0; else i=1;
	for (; i < N_words_to_print; i++)
	{
		/* Centers obtained by counting the characters, 
		 * not the bytes in the string.
		 * len = strlen(linkage->word[i]);
		 */
		len = mbstowcs(NULL, linkage->word[i], 0);
		center[i] = tot + (len/2);
		tot += len+1;
	}
}

/* the following are all for generating postscript */
typedef struct
{
	int N_rows; /* N_rows -- the number of rows */
	/* tells the height of the links above the sentence */
	int link_heights[MAX_LINKS];
	/* the word beginning each row of the display */
	int row_starts[MAX_SENTENCE];
} ps_ctxt_t;

/**
 * prints s then prints the last |t|-|s| characters of t.
 *  if s is longer than t, it truncates s.
 */
static void left_append_string(String * string, const char * s, const char * t) {
	int i, j, k;
	j = strlen(t);
	k = strlen(s);
	for (i=0; i<j; i++) {
		if (i<k) {
			append_string(string, "%c", s[i]);
		} else {
			append_string(string, "%c", t[i]);
		}
	}
}

static void print_a_link(String * s, Linkage linkage, int link)
{
	Sentence sent = linkage_get_sentence(linkage);
	Dictionary dict = sent->dict;
	int l, r;
	const char *label, *llabel, *rlabel;
	
	l      = linkage_get_link_lword(linkage, link);
	r      = linkage_get_link_rword(linkage, link);
	label  = linkage_get_link_label(linkage, link);
	llabel = linkage_get_link_llabel(linkage, link);
	rlabel = linkage_get_link_rlabel(linkage, link);

	if ((l == 0) && dict->left_wall_defined) {
		left_append_string(s, LEFT_WALL_DISPLAY,"               ");
	} else if ((l == (linkage_get_num_words(linkage)-1)) && dict->right_wall_defined) {
		left_append_string(s, RIGHT_WALL_DISPLAY,"               ");	
	} else {
		left_append_string(s, linkage_get_word(linkage, l), "               ");
	}
	left_append_string(s, llabel, "     ");
	append_string(s, "   <---"); 
	left_append_string(s, label, "-----");
	append_string(s, "->  "); 
	left_append_string(s, rlabel, "     ");
	append_string(s, "     %s\n", linkage_get_word(linkage, r));
}


/**
 * To the left of each link, print the sequence of domains it is in.
 * Printing a domain means printing its type.
 * Takes info from pp_link_array and pp and chosen_words.
 */    
char * linkage_print_links_and_domains(Linkage linkage)
{
	int link, longest, j;
	int N_links = linkage_get_num_links(linkage);
	String * s = string_new();
	char * links_string;
	char ** dname;

	longest = 0;
	for (link=0; link<N_links; link++) {
		if (linkage_get_link_lword(linkage, link) == -1) continue;
		if (linkage_get_link_num_domains(linkage, link) > longest) 
			longest = linkage_get_link_num_domains(linkage, link);
	}
	for (link=0; link<N_links; link++) {
		if (linkage_get_link_lword(linkage, link) == -1) continue;<commit_msg>fix const char * warning<commit_after>/*************************************************************************/
/* Copyright (c) 2004                                                    */
/* <NAME>, <NAME>, and <NAME>                    */
/* All rights reserved                                                   */
/*                                                                       */
/* Use of the link grammar parsing system is subject to the terms of the */
/* license set forth in the LICENSE file included with this software,    */ 
/* and also available at http://www.link.cs.cmu.edu/link/license.html    */
/* This license allows free redistribution and use in source and binary  */
/* forms, with or without modification, subject to certain conditions.   */
/*                                                                       */
/*************************************************************************/


#include <stdarg.h>
#include <link-grammar/api.h>
#include "corpus/corpus.h"

const char * trailer(int mode);
const char * header(int mode);

static void set_centers(Linkage linkage, int center[], int print_word_0, int N_words_to_print)
{
	int i, len, tot;
	tot = 0;
	if (print_word_0) i=0; else i=1;
	for (; i < N_words_to_print; i++)
	{
		/* Centers obtained by counting the characters, 
		 * not the bytes in the string.
		 * len = strlen(linkage->word[i]);
		 */
		len = mbstowcs(NULL, linkage->word[i], 0);
		center[i] = tot + (len/2);
		tot += len+1;
	}
}

/* the following are all for generating postscript */
typedef struct
{
	int N_rows; /* N_rows -- the number of rows */
	/* tells the height of the links above the sentence */
	int link_heights[MAX_LINKS];
	/* the word beginning each row of the display */
	int row_starts[MAX_SENTENCE];
} ps_ctxt_t;

/**
 * prints s then prints the last |t|-|s| characters of t.
 *  if s is longer than t, it truncates s.
 */
static void left_append_string(String * string, const char * s, const char * t) {
	int i, j, k;
	j = strlen(t);
	k = strlen(s);
	for (i=0; i<j; i++) {
		if (i<k) {
			append_string(string, "%c", s[i]);
		} else {
			append_string(string, "%c", t[i]);
		}
	}
}

static void print_a_link(String * s, Linkage linkage, int link)
{
	Sentence sent = linkage_get_sentence(linkage);
	Dictionary dict = sent->dict;
	int l, r;
	const char *label, *llabel, *rlabel;
	
	l      = linkage_get_link_lword(linkage, link);
	r      = linkage_get_link_rword(linkage, link);
	label  = linkage_get_link_label(linkage, link);
	llabel = linkage_get_link_llabel(linkage, link);
	rlabel = linkage_get_link_rlabel(linkage, link);

	if ((l == 0) && dict->left_wall_defined) {
		left_append_string(s, LEFT_WALL_DISPLAY,"               ");
	} else if ((l == (linkage_get_num_words(linkage)-1)) && dict->right_wall_defined) {
		left_append_string(s, RIGHT_WALL_DISPLAY,"               ");	
	} else {
		left_append_string(s, linkage_get_word(linkage, l), "               ");
	}
	left_append_string(s, llabel, "     ");
	append_string(s, "   <---"); 
	left_append_string(s, label, "-----");
	append_string(s, "->  "); 
	left_append_string(s, rlabel, "     ");
	append_string(s, "     %s\n", linkage_get_word(linkage, r));
}


/**
 * To the left of each link, print the sequence of domains it is in.
 * Printing a domain means printing its type.
 * Takes info from pp_link_array and pp and chosen_words.
 */    
char * linkage_print_links_and_domains(Linkage linkage)
{
	int link, longest, j;
	int N_links = linkage_get_num_links(linkage);
	String * s = string_new();
	char * links_string;
	const char ** dname;

	longest = 0;
	for (link=0; link<N_links; link++) {
		if (linkage_get_link_lword(linkage, link) == -1) continue;
		if (linkage_get_link_num_domains(linkage, link) > longest) 
			longest = linkage_get_link_num_domains(linkage, link);
	}
	for (link=0; link<N_links; link++) {
		if (linkage_get_link_lword(linkage, link) == -1) continue;
{'fraction_non_alphanumeric': 0.16626135927300653, 'fraction_numerical': 0.005119672340970178, 'mean_word_length': 2.864490603363007, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4079026', 'n_tokens_mistral': 2680, 'n_tokens_neox': 2524, 'n_words': 703}