コード例 #1
0
ファイル: problem1713.c プロジェクト: laysent/onlineJudge
int main(int argc,char *argv[]){
  int i;
  int syllable,line,flag;
  while(1){
    gets(haiku);
    /* fgets(haiku,301,stdin); */i=0; /* printf("%s\n",haiku); */
    if(strcmp(haiku,"e/o/i\n")==0 || strcmp(haiku,"e/o/i")==0)break;
    line=1;syllable=0;flag=0;i=0;
/*     printf("%s",haiku); */
    while(haiku[i]){
 /*      printf("%c",haiku[i]); */
      if(haiku[i]=='/'){
	if(line==1){
	  if(syllable!=5){
	    printf("1\n");
	    break;
	  }
	  else{
	    line++;flag=0;
	    syllable=0;
	  }
	}
	else if(line==2){
	  if(syllable!=7){
	    printf("2\n");
	    break;
	  }
	  else{
	    line++;flag=0;
	    syllable=0;
	  }
	}
      }
      if(haiku[i]=='\n')break;
      if(isSyllable(haiku[i]) && flag==0){
	flag=1;
	syllable++;
      }
      if(!isSyllable(haiku[i]))flag=0;
      i++;
    }
    if(line==3)
      if(syllable==5)
      printf("Y\n");
    else
      printf("3\n");
  }
  return 0;
}
コード例 #2
0
ファイル: OTGrammar_ex_metrics.cpp プロジェクト: Crisil/praat
static void replaceOutput (OTGrammarCandidate me) {
	int abstract = FALSE;
	Melder_assert (my output != NULL);
	wchar_t newOutput [100], *q = & newOutput [0];
	for (const wchar_t *p = & my output [0]; *p != '\0'; p ++) {
		if (p [0] == ' ') {
			*q ++ = p [-1] == ']' || p [1] == '/' ? ' ' : '.';
		} else if (isSyllable (p [0])) {
			*q ++ = 'c';
			if (abstract) {
				*q ++ = 'V';
				if (isStress (p [1])) {
					*q ++ = p [1];
				}
				if (p [0] == 'L') {
					;
				} else if (p [0] == 'H') {
					*q ++ = 'V';
				} else if (p [0] == 'K') {
					*q ++ = 'c';
				} else {
					*q ++ = 'C';
				}
			} else {
				*q ++ = 'v';
				if (p [0] == 'L') {
					;
				} else if (p [0] == 'H') {
					*q ++ = ':';
				} else {
					*q ++ = 'c';
				}
			}
		} else if (isStress (p [0]) && abstract) {
			;
		} else {
			if (p [0] == '/') abstract = TRUE;
			*q ++ = p [0];
		}
	}
	*q = '\0';
	Melder_free (my output);
	my output = Melder_wcsdup_f (newOutput);
}
コード例 #3
0
ファイル: dict.c プロジェクト: adriannye/python_rhyme
struct WordEntry *stringToWordEntry(char *string) {
  struct WordEntry *toreturn;
  struct StringPart *parts;
  struct StringPart *current;

  parts = getStringParts(string, 0, strlen(string));

  if (countStringParts(parts) < 2) return NULL;

  toreturn = (struct WordEntry *)testalloc(sizeof(struct WordEntry));

  toreturn->word = parts;
  toreturn->phonemes = parts->next;
  toreturn->rhymekey = NULL;

  toreturn->syllables = 0;

  for (current = parts->next ; current != NULL ;
       current = current->next) {
    if (isSyllable(current)) {
      toreturn->syllables++;
      if (isPrimaryStress(current))
	toreturn->rhymekey = current;
    }
  }

  /*words without primary keys are dropped entirely
  if (toreturn->rhymekey == NULL) {
    free(toreturn);
    return NULL;
    }*/

  toreturn->alternate = NULL;

  toreturn->string = string;

  return toreturn;
}
コード例 #4
0
ファイル: OTGrammar_ex_metrics.cpp プロジェクト: Crisil/praat
static void computeViolationMarks (OTGrammarCandidate me) {
	#define isHeavy(s)  ((s) == 'H' || (s) == 'J')
	#define isLight(s)  ((s) == 'L' || (s) == 'K')
	#define isSyllable(s)  (isHeavy (s) || isLight (s))
	#define isStress(s)  ((s) == '1' || (s) == '2')
	int depth;
	wchar_t *firstSlash = wcschr (my output, '/');
	wchar_t *lastSlash = & my output [wcslen (my output) - 1];
	my marks = NUMvector <int> (1, my numberOfConstraints = NUMBER_OF_CONSTRAINTS);
	/* Violations of WSP: count all H not followed by 1 or 2. */
	for (wchar_t *p = firstSlash + 1; p != lastSlash; p ++) {
		if (isHeavy (p [0]) && ! isStress (p [1]))
			my marks [WSP] ++;
	}
	/* Violations of FtNonfinal: count all heads followed by ). */
	for (wchar_t *p = firstSlash + 1; p != lastSlash; p ++) {
		if (isStress (p [0]) && p [1] == ')')
			my marks [FtNonfinal] ++;
	}
	/* Violations of Iambic: count all heads not followed by ). */
	for (wchar_t *p = firstSlash + 1; p != lastSlash; p ++) {
		if (isStress (p [0]) && p [1] != ')')
			my marks [Iambic] ++;
	}
	/* Violations of Parse and Peripheral: count all syllables not between (). */
	depth = 0;
	for (wchar_t *p = firstSlash + 1; p != lastSlash; p ++) {
		if (p [0] == '(') depth ++;
		else if (p [0] == ')') depth --;
		else if (isSyllable (p [0]) && depth != 1) {
			my marks [Parse] ++;
			if (p != firstSlash + 1 && p != lastSlash - 1)
				my marks [Peripheral] ++;
		}
	}
	/* Violations of FootBin: count all (L1) and (L2). */
	for (wchar_t *p = firstSlash + 1; p != lastSlash; p ++) {
		if (isLight (p [0]) && p [-1] == '(' && isStress (p [1]) && p [2] == ')')
			my marks [FootBin] ++;
	}
	/* Violations of WFL: count all initial / not followed by (. */
	if (firstSlash [1] != '(')
		my marks [WFL] = 1;
	/* Violations of WFR: count all final / not preceded by ). */
	if (lastSlash [-1] != ')')
		my marks [WFR] = 1;
	/* Violations of Main_L: count syllables from foot containing X1 to left edge. */
	{
		wchar_t *p = wcschr (firstSlash, '1');
		for (; *p != '('; p --) { }
		for (; p != firstSlash; p --) {
			if (isSyllable (p [0]))
				my marks [Main_L] ++;
		}
	}
	/* Violations of Main_R: count syllables from foot containing X1 to right edge. */
	{
		wchar_t *p = wcschr (firstSlash, '1');
		for (; *p != ')'; p ++) { }
		for (; p != lastSlash; p ++) {
			if (isSyllable (p [0]))
				my marks [Main_R] ++;
		}
	}
	/* Violations of AFL: count syllables from every foot to left edge. */
	for (wchar_t *p = firstSlash + 1; p != lastSlash; p ++) {
		if (p [0] == '(') {
			for (wchar_t *q = p; q != firstSlash; q --) {
				if (isSyllable (q [0]))
					my marks [AFL] ++;
			}
		}
	}
	/* Violations of AFR: count syllables from every foot to right edge. */
	for (wchar_t *p = firstSlash + 1; p != lastSlash; p ++) {
		if (p [0] == ')') {
			for (wchar_t *q = p; q != lastSlash; q ++) {
				if (isSyllable (q [0]))
					my marks [AFR] ++;
			}
		}
	}
	/* Violations of Nonfinal: count all final / preceded by ). */
	if (lastSlash [-1] == ')')
		my marks [Nonfinal] = 1;
	/* Violations of Trochaic: count all heads not preceded by (. */
	for (wchar_t *p = firstSlash + 1; p != lastSlash; p ++) {
		if (isStress (p [0]) && p [-2] != '(')
			my marks [Trochaic] ++;
	}
	/* Violations of FootBimoraic: count weight between (). */
	for (wchar_t *p = firstSlash + 1; p != lastSlash; p ++) {
		if (p [0] == '(') {
			int weight = 0;
			for (p ++; p [0] != ')'; p ++) {
				if (isHeavy (p [0])) weight += 2;
				else if (isLight (p [0])) weight += 1;
			}
			if (weight != 2) my marks [FootBimoraic] ++;
		}
	}
	/* Violations of FootBisyllabic: count all (X1) and (X2). */
	for (wchar_t *p = firstSlash + 1; p != lastSlash; p ++) {
		if (isSyllable (p [0]) && p [-1] == '(' && isStress (p [1]) && p [2] == ')')
			my marks [FootBisyllabic] ++;
	}
	/* Violations of MainNonfinal: count all final / preceded by ) preceded by 1 in the same foot. */
	if (lastSlash [-1] == ')') {
		for (wchar_t *p = lastSlash - 2; ; p --) {
			if (p [0] == '2') break;
			if (p [0] == '1') {
				my marks [MainNonfinal] = 1;
				break;
			}
		}
	}
	/* Violations of HeadNonfinal: count all final / preceded by ) directly preceded by 1, plus MainNonfinal. */
	if (lastSlash [-1] == ')') {
		if (lastSlash [-2] == '1') {
			my marks [HeadNonfinal] = 2;
		} else {
			for (wchar_t *p = lastSlash - 2; ; p --) {
				if (p [0] == '2') break;
				if (p [0] == '1') {
					my marks [HeadNonfinal] = 1;
					break;
				}
			}
		}
	}
	/* Violations of *Clash: count all 1 and 2 followed by an 1 or 2 after the next L or H. */
	for (wchar_t *p = firstSlash + 1; p != lastSlash; p ++) {
		if (isStress (p [0])) {
			for (wchar_t *q = p + 1; q != lastSlash; q ++) {
				if (isSyllable (q [0])) {
					if (isStress (q [1])) {
						my marks [Clash] ++;
					}
					break;
				}
			}
		}
	}
	/* Violations of *Lapse: count all sequences of three unstressed syllables. */
	depth = 0;
	for (wchar_t *p = firstSlash + 1; p != lastSlash; p ++) {
		if (isSyllable (p [0])) {
			if (isStress (p [1])) {
				depth = 0;
			} else {
				if (++ depth > 2) {
					my marks [Lapse] ++;
				}
			}
		}
	}
	/* Violations of WeightByPosition: count all K. */
	for (wchar_t *p = firstSlash + 1; p != lastSlash; p ++) {
		if (p [0] == 'K')
			my marks [WeightByPosition] ++;
	}
	/* Violations of *MoraicConsonant: count all J. */
	for (wchar_t *p = firstSlash + 1; p != lastSlash; p ++) {
		if (p [0] == 'J')
			my marks [MoraicConsonant] ++;
	}
}