Ejemplo n.º 1
0
void LabelDeEn(const Phrase &source, ostream &out)
{
  Ranges ranges;

  // find ranges to label
  for (int start = 0; start < source.size(); ++start) {
    for (int end = start; end < source.size(); ++end) {
     if (IsA(source, start, -1, 1, "VAFIN")
          && IsA(source, end, +1, 1, "VVINF VVPP")
          && !Contains(source, start, end, 1, "VAFIN VVINF VVPP VVFIN")) {
       Range range(start, end, "reorder-label");
       ranges.push_back(range);
      }
      else if ((start == 0 || IsA(source, start, -1, 1, "$,"))
          && IsA(source, end, +1, 0, "zu")
          && IsA(source, end, +2, 1, "VVINF")
          && !Contains(source, start, end, 1, "$,")) {
        Range range(start, end, "reorder-label");
        ranges.push_back(range);
      }
    }
  }

  OutputWithLabels(source, ranges, out);
}
Ejemplo n.º 2
0
void initPropRanges(Ranges &propRanges, const ColorRanges &ranges, int p) {
    propRanges.clear();
    int min = ranges.min(p);
    int max = ranges.max(p);
    int mind = min - max, maxd = max - min;
    if (p < 3) {       // alpha channel first
      for (int pp = 0; pp < p; pp++) {
        propRanges.push_back(std::make_pair(ranges.min(pp), ranges.max(pp)));  // pixels on previous planes
      }
      if (ranges.numPlanes()>3) propRanges.push_back(std::make_pair(ranges.min(3), ranges.max(3)));  // pixel on alpha plane
    }

    //if (p<1 || p>2) 
    propRanges.push_back(std::make_pair(0,2));       // median predictor: which of the three values is the median?

    if (p==1 || p==2) propRanges.push_back(std::make_pair(ranges.min(0)-ranges.max(0),ranges.max(0)-ranges.min(0))); // luma prediction miss
    propRanges.push_back(std::make_pair(mind,maxd)); // neighbor A - neighbor B   (top-bottom or left-right)
    propRanges.push_back(std::make_pair(mind,maxd)); // top/left prediction miss (previous pixel)
    propRanges.push_back(std::make_pair(mind,maxd)); // left/top prediction miss (other direction)
    propRanges.push_back(std::make_pair(mind,maxd)); // bottom/right prediction miss
    propRanges.push_back(std::make_pair(min,max));   // guess

//    propRanges.push_back(std::make_pair(mind,maxd));  // left - topleft
//    propRanges.push_back(std::make_pair(mind,maxd));  // topleft - top

//    if (p == 0 || p > 2)
//      propRanges.push_back(std::make_pair(mind,maxd)); // top - topright
    if (p != 2) {
      propRanges.push_back(std::make_pair(mind,maxd)); // toptop - top
      propRanges.push_back(std::make_pair(mind,maxd)); // leftleft - left
    }
}
Ejemplo n.º 3
0
void initPropRanges(Ranges &propRanges, const ColorRanges &ranges, int p) {
    propRanges.clear();
    int min = ranges.min(p);
    int max = ranges.max(p);
    int mind = min - max, maxd = max - min;
    if (p < 3) {       // alpha channel first
      for (int pp = 0; pp < p; pp++) {
        propRanges.push_back(std::make_pair(ranges.min(pp), ranges.max(pp)));  // pixels on previous planes
      }
      if (ranges.numPlanes()>3) propRanges.push_back(std::make_pair(ranges.min(3), ranges.max(3)));  // pixel on alpha plane
    }
    propRanges.push_back(std::make_pair(mind,maxd)); // neighbor A - neighbor B   (top-bottom or left-right)
    propRanges.push_back(std::make_pair(min,max));   // guess (median of 3)
    propRanges.push_back(std::make_pair(0,2));       // which predictor was it
    propRanges.push_back(std::make_pair(mind,maxd));
    propRanges.push_back(std::make_pair(mind,maxd));
    propRanges.push_back(std::make_pair(mind,maxd));

    if (p < 2 || p >= 3) {
      propRanges.push_back(std::make_pair(mind,maxd));
      propRanges.push_back(std::make_pair(mind,maxd));
    }
}
Ejemplo n.º 4
0
void initPropRanges_scanlines(Ranges &propRanges, const ColorRanges &ranges, int p) {
    propRanges.clear();
    int min = ranges.min(p);
    int max = ranges.max(p);
    int mind = min - max, maxd = max - min;

    if (p < 3) {
      for (int pp = 0; pp < p; pp++) {
        propRanges.push_back(std::make_pair(ranges.min(pp), ranges.max(pp)));  // pixels on previous planes
      }
      if (ranges.numPlanes()>3) propRanges.push_back(std::make_pair(ranges.min(3), ranges.max(3)));  // pixel on alpha plane
    }
    propRanges.push_back(std::make_pair(min,max));   // guess (median of 3)
    propRanges.push_back(std::make_pair(0,2));       // which predictor was it
    propRanges.push_back(std::make_pair(mind,maxd));
    propRanges.push_back(std::make_pair(mind,maxd));
    propRanges.push_back(std::make_pair(mind,maxd));
    propRanges.push_back(std::make_pair(mind,maxd));
    propRanges.push_back(std::make_pair(mind,maxd));
}
Ejemplo n.º 5
0
Parfactor*
readParfactor (YAP_Term pfTerm)
{
  // read dist id
  unsigned distId = YAP_IntOfTerm (YAP_ArgOfTerm (1, pfTerm));

  // read the ranges
  Ranges ranges;
  YAP_Term rangeList = YAP_ArgOfTerm (3, pfTerm);
  while (rangeList != YAP_TermNil()) {
    unsigned range = (unsigned) YAP_IntOfTerm (YAP_HeadOfTerm (rangeList));
    ranges.push_back (range);
    rangeList = YAP_TailOfTerm (rangeList);
  }

  // read parametric random vars
  ProbFormulas formulas;
  unsigned count = 0;
  unordered_map<YAP_Term, LogVar> lvMap;
  YAP_Term pvList = YAP_ArgOfTerm (2, pfTerm);
  while (pvList != YAP_TermNil()) {
    YAP_Term formulaTerm = YAP_HeadOfTerm (pvList);
    if (YAP_IsAtomTerm (formulaTerm)) {
      string name ((char*) YAP_AtomName (YAP_AtomOfTerm (formulaTerm)));
      Symbol functor = LiftedUtils::getSymbol (name);
      formulas.push_back (ProbFormula (functor, ranges[count]));
    } else {
      LogVars logVars;
      YAP_Functor yapFunctor = YAP_FunctorOfTerm (formulaTerm);
      string name ((char*) YAP_AtomName (YAP_NameOfFunctor (yapFunctor)));
      Symbol functor = LiftedUtils::getSymbol (name);
      unsigned arity = (unsigned) YAP_ArityOfFunctor (yapFunctor);
      for (unsigned i = 1; i <= arity; i++) {
        YAP_Term ti = YAP_ArgOfTerm (i, formulaTerm);
        unordered_map<YAP_Term, LogVar>::iterator it = lvMap.find (ti);
        if (it != lvMap.end()) {
          logVars.push_back (it->second);
        } else {
         unsigned newLv = lvMap.size();
         lvMap[ti] = newLv;
         logVars.push_back (newLv);
        }
      }
      formulas.push_back (ProbFormula (functor, logVars, ranges[count]));
    }
    count ++;
    pvList = YAP_TailOfTerm (pvList);
  }

  // read the parameters
  const Params& params = readParameters (YAP_ArgOfTerm (4, pfTerm)); 

  // read the constraint
  Tuples tuples;
  if (lvMap.size() >= 1) {
    YAP_Term tupleList = YAP_ArgOfTerm (5, pfTerm);
    while (tupleList != YAP_TermNil()) {
      YAP_Term term = YAP_HeadOfTerm (tupleList);
      assert (YAP_IsApplTerm (term));
      YAP_Functor yapFunctor = YAP_FunctorOfTerm (term);
      unsigned arity = (unsigned) YAP_ArityOfFunctor (yapFunctor);
      assert (lvMap.size() == arity);
      Tuple tuple (arity);
      for (unsigned i = 1; i <= arity; i++) {
        YAP_Term ti = YAP_ArgOfTerm (i, term);
        if (YAP_IsAtomTerm (ti) == false) {
          cerr << "error: constraint has free variables" << endl;
          abort();
        }
        string name ((char*) YAP_AtomName (YAP_AtomOfTerm (ti)));
        tuple[i - 1] = LiftedUtils::getSymbol (name);
      }
      tuples.push_back (tuple);
      tupleList = YAP_TailOfTerm (tupleList);
    }
  }
  return new Parfactor (formulas, params, tuples, distId);
}
Ejemplo n.º 6
0
void EnPhrasalVerb(const Phrase &source, int revision, ostream &out)
{
  Ranges ranges;

  // find ranges to label
  for (int start = 0; start < source.size(); ++start) {
	size_t end = std::numeric_limits<size_t>::max();

	if (IsA(source, start, 0, 0, "ask asked asking")) {
		end = Found(source, start, 0, "out");
    }
	else if (IsA(source, start, 0, 0, "back backed backing")) {
		end = Found(source, start, 0, "up");
	}
	else if (IsA(source, start, 0, 0, "blow blown blew")) {
		end = Found(source, start, 0, "up");
	}
	else if (IsA(source, start, 0, 0, "break broke broken")) {
		end = Found(source, start, 0, "down up in");
	}
	else if (IsA(source, start, 0, 0, "bring brought bringing")) {
		end = Found(source, start, 0, "down up in");
	}
	else if (IsA(source, start, 0, 0, "call called calling")) {
		end = Found(source, start, 0, "back up off");
	}
	else if (IsA(source, start, 0, 0, "check checked checking")) {
		end = Found(source, start, 0, "out in");
	}
	else if (IsA(source, start, 0, 0, "cheer cheered cheering")) {
		end = Found(source, start, 0, "up");
	}
	else if (IsA(source, start, 0, 0, "clean cleaned cleaning")) {
		end = Found(source, start, 0, "up");
	}
	else if (IsA(source, start, 0, 0, "cross crossed crossing")) {
		end = Found(source, start, 0, "out");
	}
	else if (IsA(source, start, 0, 0, "cut cutting")) {
		end = Found(source, start, 0, "down off out");
	}
	else if (IsA(source, start, 0, 0, "do did done")) {
		end = Found(source, start, 0, "over up");
	}
	else if (IsA(source, start, 0, 0, "drop dropped dropping")) {
		end = Found(source, start, 0, "off");
	}
	else if (IsA(source, start, 0, 0, "figure figured figuring")) {
		end = Found(source, start, 0, "out");
	}
	else if (IsA(source, start, 0, 0, "fill filled filling")) {
		end = Found(source, start, 0, "in out up");
	}
	else if (IsA(source, start, 0, 0, "find found finding")) {
		end = Found(source, start, 0, "out");
	}
	else if (IsA(source, start, 0, 0, "get got getting gotten")) {
		end = Found(source, start, 0, "across over back");
	}
	else if (IsA(source, start, 0, 0, "give given gave giving")) {
		end = Found(source, start, 0, "away back out up");
	}
	else if (IsA(source, start, 0, 0, "hand handed handing")) {
		end = Found(source, start, 0, "down in over");
	}
	else if (IsA(source, start, 0, 0, "hold held holding")) {
		end = Found(source, start, 0, "back up");
	}
	else if (IsA(source, start, 0, 0, "keep kept keeping")) {
		end = Found(source, start, 0, "from up");
	}
	else if (IsA(source, start, 0, 0, "let letting")) {
		end = Found(source, start, 0, "down in");
	}
	else if (IsA(source, start, 0, 0, "look looked looking")) {
		end = Found(source, start, 0, "over up");
	}
	else if (IsA(source, start, 0, 0, "make made making")) {
		end = Found(source, start, 0, "up");
	}
	else if (IsA(source, start, 0, 0, "mix mixed mixing")) {
		end = Found(source, start, 0, "up");
	}
	else if (IsA(source, start, 0, 0, "pass passed passing")) {
		end = Found(source, start, 0, "out up");
	}
	else if (IsA(source, start, 0, 0, "pay payed paying")) {
		end = Found(source, start, 0, "back");
	}
	else if (IsA(source, start, 0, 0, "pick picked picking")) {
		end = Found(source, start, 0, "out");
	}
	else if (IsA(source, start, 0, 0, "point pointed pointing")) {
		end = Found(source, start, 0, "out");
	}
	else if (IsA(source, start, 0, 0, "put putting")) {
		end = Found(source, start, 0, "down off out together on");
	}
	else if (IsA(source, start, 0, 0, "send sending")) {
		end = Found(source, start, 0, "back");
	}
	else if (IsA(source, start, 0, 0, "set setting")) {
		end = Found(source, start, 0, "up");
	}
	else if (IsA(source, start, 0, 0, "sort sorted sorting")) {
		end = Found(source, start, 0, "out");
	}
	else if (IsA(source, start, 0, 0, "switch switched switching")) {
		end = Found(source, start, 0, "off on");
	}
	else if (IsA(source, start, 0, 0, "take took taking")) {
		end = Found(source, start, 0, "apart back off out");
	}
	else if (IsA(source, start, 0, 0, "tear torn tearing")) {
		end = Found(source, start, 0, "up");
	}
	else if (IsA(source, start, 0, 0, "think thought thinking")) {
		end = Found(source, start, 0, "over");
	}
	else if (IsA(source, start, 0, 0, "thrown threw thrown throwing")) {
		end = Found(source, start, 0, "away");
	}
	else if (IsA(source, start, 0, 0, "turn turned turning")) {
		end = Found(source, start, 0, "down off on");
	}
	else if (IsA(source, start, 0, 0, "try tried trying")) {
		end = Found(source, start, 0, "on out");
	}
	else if (IsA(source, start, 0, 0, "use used using")) {
		end = Found(source, start, 0, "up");
	}
	else if (IsA(source, start, 0, 0, "warm warmed warming")) {
		end = Found(source, start, 0, "up");
	}
	else if (IsA(source, start, 0, 0, "work worked working")) {
		end = Found(source, start, 0, "out");
	}

	// found range to label
	if (end != std::numeric_limits<size_t>::max() &&
			end > start + 1) {
		bool add = true;
		if (revision == 1 && Exist(source,
									start + 1,
									end - 1,
									1,
									"VB VBD VBG VBN VBP VBZ")) {
			// there's a verb in between
			add = false;
		}

		if (add) {
			Range range(start + 1, end - 1, "reorder-label");
			ranges.push_back(range);
		}
	}
  }

  OutputWithLabels(source, ranges, out);
}