示例#1
0
文件: lib.c 项目: mohnkhan/summarizer
string_t
get_word_stem(array_t** stack, lang_t* lang, const string_t word, bool_t is_core)
{
    string_t  changed, copy, *r;
    array_t*  a;

    if(SMRZR_TRUE == is_core) {
        changed = word;
    } else {
        if(NULL == (changed = get_word_core(stack, lang, word)))
            return(NULL);
    }

    if(isupper(changed[0]) && strlen(changed) > 1) return(changed);

    copy = array_push_alloc(stack, strlen(changed)+1);
    strcpy(copy, changed);

    a = lang->manual;

    if(NULL!=(r=(string_t*)array_search(a, changed, comp_string_with_rule))){
        replace_word(stack, changed, *r);
    }

    a = lang->pre;

    for(r = (string_t*)ARR_FIRST(a); !ARR_END(a); r = (string_t*)ARR_NEXT(a)) {
        if(SMRZR_TRUE == replace_word_head(changed, *r)) break;
    }

    a = lang->post;

    for(r = (string_t*)ARR_FIRST(a); !ARR_END(a); r = (string_t*)ARR_NEXT(a)) {
        if(SMRZR_TRUE == replace_word_tail(changed, *r)) break;
    }

    a = lang->synonyms;

    if(NULL!=(r=(string_t*)array_search(a, changed, comp_string_with_rule))){
        replace_word(stack, changed, *r);
    }

    /* quality check */
    if(strlen(changed) < 3) {
        memmove(changed, copy, strlen(copy)+1);
        (*stack)->curr = PTR_ADD(elem_t, changed, strlen(changed)+1);
    } else {
        array_pop_free(*stack, copy);
    }

    return(changed);
}
示例#2
0
char	*replace_by_alias(char *str, t_alias *list)
{
  char	*new_str;
  char	*word;
  int	save;
  int	x;

  x = -1;
  if ((new_str = copy_str(str)) == NULL)
    return (NULL);
  while (new_str[++x])
    {
      if (new_str[x] != ';' && new_str[x] != ' ' && new_str[x] != '\t' &&
	  new_str[x] != '|' && new_str[x] != '&')
	{
	  save = x;
	  if ((word = get_a_word(new_str, &x)) && is_alias(&word, list))
	    {
	      if ((new_str = replace_word(word, new_str, save, &x)) == NULL)
		return (NULL);
	    }
	  else if (word)
	    free(word);
	}
    }
  return (new_str);
}
示例#3
0
/* simple version of C preprocessor */
int main()
{
	/* get a line
	 * check if it is a define line
	 * if so: install definition
	 * if not: check for defined names and replace
	 * print line */

	char line[MAXLINE]; /* holds the line under consideration */
	char name[MAXCHAR];
	char defn[MAXCHAR];
	struct nlist *np;
	int line_length = MAXLINE;

	char word[MAXCHAR]; /* holds the word under consideration */
	char *wordptr, *wordendptr;


	while (line_length > 0) {
		line_length = my_getline(line, MAXCHAR);
		/*printf("raw line:\t%s\n", line);*/
		if (isdefine(line, name, defn)) {
		/*	printf("found define statement\n");
		*	printf("name:\t%s\n", name);
		*	printf("defn:\t%s\n", defn); */
			install(name, defn);
		}
		else {
			wordptr = line;
			/*printf("no define found\n");*/
			while (*wordptr != '\n' && *wordptr != EOF && (wordptr - line) < MAXLINE) {
				wordendptr = getword(wordptr, word, MAXCHAR);
				/*printf("%s\n", word);*/
				np = lookup(word);
				if (np != NULL) {
					replace_word(line, wordptr, wordendptr, defn);
					wordendptr = wordptr + strlen(defn) + 1;
				}
				wordptr = wordendptr;
			}
			/* printf("processed line:\t%s\n", line);*/
		}
		printf("%s", line);
	}
	return 0;
}
示例#4
0
文件: select.c 项目: NegMozzie/42
void				setlist(t_line **list, char **str, int len)
{
	t_line			*tmp;
	int				i;

	tmp = *list;
	i = big_word(tmp) + 2;
	if (tmp && !tmp->next)
	{
		replace_word(tmp, str, len);
		ft_putchar('\r');
	}
	else if (tmp)
	{
		put_word(tmp, i);
	}
}