示例#1
0
set<string> get_parents(Function f, int stage) {
    set<string> parents;
    if (f.has_extern_definition()) {
        internal_assert(stage == 0);
        for (const ExternFuncArgument &arg : f.extern_arguments()) {
            if (arg.is_func()) {
                string prod_name = Function(arg.func).name();
                parents.insert(prod_name);
            } else if (arg.is_expr()) {
                FindAllCalls find;
                arg.expr.accept(&find);
                parents.insert(find.funcs_called.begin(), find.funcs_called.end());
            } else if (arg.is_image_param() || arg.is_buffer()) {
                Buffer<> buf;
                if (arg.is_image_param()) {
                    buf = arg.image_param.buffer();
                } else {
                    buf = arg.buffer;
                }
                parents.insert(buf.name());
            }
        }
    } else {
        FindAllCalls find;
        Definition def = get_stage_definition(f, stage);
        def.accept(&find);
        parents.insert(find.funcs_called.begin(), find.funcs_called.end());
    }
    return parents;
}
示例#2
0
  static void readGrammar(ifstream& infile, map<string, Definition>& grammar)
  {   
    // Keep parsing until EOF is reached.
    while(infile.good())
    { 
      // Ignore all chars until '{' is reached.
      infile.ignore(numeric_limits<streamsize>::max(), '{');

      // Ignore all chars until '\n' is reached.
      infile.ignore(numeric_limits<streamsize>::max(), '<');

      if(infile.good()) 
      {
        // Beginning of a definition; parse into program.
        Definition myDefinition = Definition(infile);
        
        // Fill map.
        string myNonTerminal = myDefinition.getNonterminal();
        pair<string, Definition> myPair(myNonTerminal, myDefinition);
        grammar.insert(myPair);
      }
    }

    infile.close();
}
示例#3
0
	void SubtitleFile::Parse(InputStream& s)
	{
		m_segments.RemoveAll();

		__super::Parse(s, s_predef);

		// TODO: check file.format == "ssf" and file.version == 1

		CAtlList<Definition*> defs;
		GetRootRef()->GetChildDefs(defs, L"subtitle");
		
		StringMapW<float> offset;

		POSITION pos = defs.GetHeadPosition();
		while(pos)
		{
			Definition* pDef = defs.GetNext(pos);

			try
			{
				Definition::Time time;

				if(pDef->GetAsTime(time, offset) && (*pDef)[L"@"].IsValue())
				{
					m_segments.Insert(time.start.value, time.stop.value, pDef);
				}
			}
			catch(Exception&)
			{
			}
		}
	}
示例#4
0
// Prints out an expression.
void Expression::Print(Calculator *calculator, PrintMode mode)
{
	if(!head)
		throw PrintException("Expression has no head.");
	// In standard print mode, let operator decide how expression should be printed.
	// (E.g. print Plus[a,b] as a+b.)
	if(mode == pmStandard)
	{
		Definition *def = FunctionDefinition(calculator);
		if(def && def->Predef())
		{
			def->Predef()->PrintExpression(this, calculator, mode);
			return;
		}
	}
	// If expression has no linked operator or print mode is FullForm, simply print
	// head and leaves. If head is no Atom, we have to put it in parentheses.
	if(!head->IsAtom() && !dynamic_cast<Atom*>(head))
		cout << "(";
	head->Print(calculator, mode);
	if(!head->IsAtom() && !dynamic_cast<Atom*>(head))
		cout << ")";
	if(!dynamic_cast<Atom*>(head))
	{
		cout << "[";
		for(ExprVector::const_iterator leaf = leaves.begin(); leaf != leaves.end(); ++leaf)
		{
			if(leaf != leaves.begin())
				cout << ", ";
			(*leaf)->Print(calculator, mode);
		}
		cout << "]";
	}
}
示例#5
0
Definition& Definition::operator[](LPCWSTR type)
{
    Definition* pRetDef = NULL;
    if(m_type2def.Lookup(type, pRetDef))
        return *pRetDef;

    pRetDef = DNew Definition(m_pnf, L"");
    pRetDef->m_priority = PLow;
    pRetDef->m_type = type;
    m_type2def[type] = pRetDef;

    CAtlList<Definition*> l;
    GetChildDefs(l, type);

    while(!l.IsEmpty())
    {
        Definition* pDef = l.RemoveHead();

        pRetDef->m_priority = pDef->m_priority;
        pRetDef->m_parent = pDef->m_parent;

        if(pDef->IsValue())
        {
            pRetDef->SetAsValue(pDef->m_status, pDef->m_value, pDef->m_unit);
        }
        else
        {
            pRetDef->m_status = node;
            pRetDef->m_nodes.AddTailList(&pDef->m_nodes);
        }
    }

    return *pRetDef;
}
示例#6
0
double Cos(Definition &def1, Definition &def2)
{
	std::map<unsigned long long, int>::iterator itr;
	std::set<unsigned long long> words;
	std::set<unsigned long long>::iterator itrSet;

	double numerator = 0.0;
	double denominatorA = 0.0;
	double denominatorB = 0.0;

	int numeratorInt = 0;
	int denominatorAInt = 0;
	int denominatorBInt = 0;

	double a,b;
	int aInt,bInt;

	for(itr = def1.mappedWords.begin(); itr != def1.mappedWords.end(); ++itr)
		words.insert(itr->first);
	for(itr = def2.mappedWords.begin(); itr != def2.mappedWords.end(); ++itr)
		words.insert(itr->first);

	unsigned long long wrd;

	//if (globalArgs.normalizationType == TF_IDF || globalArgs.normalizationType == UnitLenght || globalArgs.normalizationType == LogEntropy)
	if (globalArgs.normalizationType != None)
	{
		for(itrSet = words.begin(); itrSet != words.end(); ++itrSet)
		{
			wrd = *itrSet;

			a = ((double)def1.Frequency(wrd))/0x0FFFFFF;
			b = ((double)def2.Frequency(wrd))/0x0FFFFFF;

			numerator += a*b;
			denominatorA += a*a;
			denominatorB += b*b;
		}
	
		double denominator = sqrt((double)denominatorA) *  sqrt((double)denominatorB);
		return numerator / denominator;
	}
	else
	{
		for(itrSet = words.begin(); itrSet != words.end(); ++itrSet)
		{
			wrd = *itrSet;

			aInt = def1.Frequency(wrd);
			bInt = def2.Frequency(wrd);

			numeratorInt += aInt*bInt;
			denominatorAInt += aInt*aInt;
			denominatorBInt += bInt*bInt;
		}
	
		double denominator = sqrt((double)denominatorAInt) *  sqrt((double)denominatorBInt);
		return numeratorInt / denominator;
	}
}
示例#7
0
 void register_function(Context& ctx, Signature sig, Native_Function f, size_t arity, Env* env)
 {
   Definition* def = make_native_function(sig, f, ctx);
   stringstream ss;
   ss << def->name() << "[f]" << arity;
   def->environment(env);
   (*env)[ss.str()] = def;
 }
示例#8
0
 void extract_constant_macro_info(Token const& name, Definition const& definition)
 {
     if (definition.size() != 1 || !is_constant_integer(detail::to_string(definition.front().get_value()))) {
         std::cout << name.get_value() << " is not constant" << std::endl;
         return;
     }
     constant_macros_.emplace_back(detail::to_string(name.get_value()), detail::to_string(definition.front().get_value()));
 }
示例#9
0
Definition* Definition::SetChildAsNumber(CStringW path, CStringW v, CStringW u)
{
    Definition* pDef = SetChildAsValue(path, number, v, u);

    Number<float> n;
    pDef->GetAsNumber(n); // will throw an exception if not a number

    return pDef;
}
示例#10
0
 Statement* Expand::operator()(Definition* d)
 {
   Definition* dd = new (ctx.mem) Definition(*d);
   env->current_frame()[d->name() +
                       (d->type() == Definition::MIXIN ? "[m]" : "[f]")] = dd;
   // set the static link so we can have lexical scoping
   dd->environment(env);
   return 0;
 }
示例#11
0
文件: rsg.cpp 项目: AndrewWUw/cs6771
static void generateRandomSentences(const map<string, Definition>& grammar,
		int numSentencesNeeded) {
	for (int i = 0; i < numSentencesNeeded; ++i) {
		Definition defin = grammar.at("<start>");

		Production prod = defin.getRandomProduction();
		expendProduction(prod, grammar);
		cout << endl;
	}
}
示例#12
0
Predefined *Expression::PredefFunc(Calculator *calculator)
{
	if(head)
	{
		Definition *def = FunctionDefinition(calculator);
		if(def)
			return def->Predef();
	}
	return 0;
}
示例#13
0
vector<Dim> &get_stage_dims(const Function &f, int stage_num) {
    static vector<Dim> outermost_only =
        {{Var::outermost().name(), ForType::Serial, DeviceAPI::None, Dim::Type::PureVar}};
    if (f.has_extern_definition()) {
        return outermost_only;
    }
    Definition def = get_stage_definition(f, stage_num);
    internal_assert(def.defined());
    return def.schedule().dims();
}
示例#14
0
 void register_c_function(Context& ctx, Env* env, Sass_C_Function_Callback descr)
 {
   Definition* def = make_c_function(
     sass_function_get_signature(descr),
     sass_function_get_function(descr),
     sass_function_get_cookie(descr),
     ctx
   );
   def->environment(env);
   (*env)[def->name() + "[f]"] = def;
 }
示例#15
0
static void expandOn(const map<string, Definition>& grammar, int aNonTerminalPos, vector<string>& aResult)
{
    if(aNonTerminalPos == -1)
    {
      // Base case //
      
      return;
    }
    else
    { 
      // Recursive case //

      auto iterator = grammar.find(aResult[aNonTerminalPos]);

      // If non-terminal is not defined then display error msg and exit.
      if(iterator == grammar.end()) {
        cout << "Could not find \"" << aResult[aNonTerminalPos] << "\" in the grammar file." << endl;
        exit (EXIT_FAILURE);  
      }

      Definition myDefinition = iterator->second;

      Production myRandProduction = myDefinition.getRandomProduction();
      
      // Get iterator 1 passed pos to insert.
      auto resultIterator = aResult.begin()+aNonTerminalPos+1;
      aResult.insert(resultIterator, myRandProduction.begin(), myRandProduction.end());
      
      // Get new valid iterator and delete expanded non-terminal.
      resultIterator = aResult.begin()+aNonTerminalPos;
      aResult.erase(resultIterator);

      // Iterate through result vector to expand on non-terminals.
      // Start from previously expanded position.
      int newNonTerminalPos = -1;
      int pos = aNonTerminalPos;
      for(auto start = aResult.begin()+aNonTerminalPos; start != aResult.end(); start++)
      {
        // Check if non-terminal.
        if( (*start)[0] == '<')
        {
          newNonTerminalPos = pos;
          break;
        }
        pos++;
      }
      
      // Recurse.      
      expandOn(grammar, newNonTerminalPos, aResult);
    }
}
示例#16
0
QCString Definition::qualifiedName() const
{
  static int count=0;
  count++;
  makeResident();
  if (!m_impl->qualifiedName.isEmpty()) 
  {
    count--;
    return m_impl->qualifiedName;
  }
#if 0
  if (count>20)
  {
    printf("Definition::qualifiedName() Infinite recursion detected! Type=%d\n",definitionType());
    printf("Trace:\n");
    Definition *d = (Definition *)this;
    for (int i=0;d && i<20;i++)
    {
      printf("  %s\n",d->name().data());
      d = d->getOuterScope();
    }
  }
#endif
  
  //printf("start %s::qualifiedName() localName=%s\n",name().data(),m_impl->localName.data());
  if (m_impl->outerScope==0) 
  {
    if (m_impl->localName=="<globalScope>") 
    {
      count--;
      return "";
    }
    else 
    {
      count--;
      return m_impl->localName; 
    }
  }

  if (m_impl->outerScope->name()=="<globalScope>")
  {
    m_impl->qualifiedName = m_impl->localName;
  }
  else
  {
    m_impl->qualifiedName = m_impl->outerScope->qualifiedName()+"::"+m_impl->localName;
  }
  //printf("end %s::qualifiedName()=%s\n",name().data(),m_impl->qualifiedName.data());
  count--;
  return m_impl->qualifiedName;
};
示例#17
0
文件: rsg.cpp 项目: AndrewWUw/cs6771
static void expendProduction(Production& production, const map<string, Definition>& grammar) {

	for (auto iter = production.begin(); iter < production.end(); ++iter) {
		string str = *iter;

		if (str.find('<') == std::string::npos) {
			cout << str << " ";
		} else {
			Definition def = grammar.at(str);
			Production prod = def.getRandomProduction();
			expendProduction(prod, grammar);
		}
	}
}
示例#18
0
    // Check if the dimension at index 'dim_idx' is always pure (i.e. equal to 'dim')
    // in the definition (including in its specializations)
    bool is_dim_always_pure(const Definition &def, const string& dim, int dim_idx) {
        const Variable *var = def.args()[dim_idx].as<Variable>();
        if ((!var) || (var->name != dim)) {
            return false;
        }

        for (const auto &s : def.specializations()) {
            bool pure = is_dim_always_pure(s.definition, dim, dim_idx);
            if (!pure) {
                return false;
            }
        }
        return true;
    }
示例#19
0
void
TreeContext::updateDecl(JSAtom *atom, ParseNode *pn)
{
    Definition *oldDecl = decls_.lookupFirst(atom);

    pn->setDefn(true);
    Definition *newDecl = (Definition *)pn;
    decls_.updateFirst(atom, newDecl);

    if (!sc->inFunction()) {
        JS_ASSERT(newDecl->isFreeVar());
        return;
    }

    JS_ASSERT(oldDecl->isBound());
    JS_ASSERT(!oldDecl->pn_cookie.isFree());
    newDecl->pn_cookie = oldDecl->pn_cookie;
    newDecl->pn_dflags |= PND_BOUND;
    if (JOF_OPTYPE(oldDecl->getOp()) == JOF_QARG) {
        newDecl->setOp(JSOP_GETARG);
        JS_ASSERT(args_[oldDecl->pn_cookie.slot()] == oldDecl);
        args_[oldDecl->pn_cookie.slot()] = newDecl;
    } else {
        JS_ASSERT(JOF_OPTYPE(oldDecl->getOp()) == JOF_LOCAL);
        newDecl->setOp(JSOP_GETLOCAL);
        JS_ASSERT(vars_[oldDecl->pn_cookie.slot()] == oldDecl);
        vars_[oldDecl->pn_cookie.slot()] = newDecl;
    }
}
示例#20
0
	void File::ParseDefs(InputStream& s, Reference* pParentRef)
	{
		while(s.SkipWhiteSpace(L";") != '}' && s.PeekChar() != Stream::EOS)
		{
			NodePriority priority = PNormal;
			CAtlList<CStringW> types;
			CStringW name;

			int c = s.SkipWhiteSpace();

			if(c == '*') {s.GetChar(); priority = PLow;}
			else if(c == '!') {s.GetChar(); priority = PHigh;}

			ParseTypes(s, types);

			if(s.SkipWhiteSpace() == '#')
			{
				s.GetChar();
				ParseName(s, name);
			}

			if(types.IsEmpty())
			{
				if(name.IsEmpty()) s.ThrowError(_T("syntax error"));
				types.AddTail(L"?");
			}

			Reference* pRef = pParentRef;

			while(types.GetCount() > 1)
				pRef = CreateRef(CreateDef(pRef, types.RemoveHead()));

			Definition* pDef = NULL;

			if(!types.IsEmpty())
				pDef = CreateDef(pRef, types.RemoveHead(), name, priority);

			c = s.SkipWhiteSpace(L":=");

			if(c == '"' || c == '\'') ParseQuotedString(s, pDef);
			else if(iswdigit(c) || c == '+' || c == '-') ParseNumber(s, pDef);
			else if(pDef->IsType(L"@")) ParseBlock(s, pDef);
			else ParseRefs(s, pDef);
		}

		s.GetChar();
	}
示例#21
0
Definition* Definition::SetChildAsValue(CStringW path, status_t s, CStringW v, CStringW u)
{
    Definition* pDef = this;

    Split split('.', path);

    for(size_t i = 0, j = split - 1; i <= j; i++)
    {
        CStringW type = split[i];

        if(pDef->m_nodes.IsEmpty() || !dynamic_cast<Reference*>(pDef->m_nodes.GetTail()))
        {
            EXECUTE_ASSERT(m_pnf->CreateRef(pDef) != NULL);
        }

        if(Reference* pRef = dynamic_cast<Reference*>(pDef->m_nodes.GetTail()))
        {
            pDef = NULL;

            POSITION pos = pRef->m_nodes.GetTailPosition();
            while(pos)
            {
                Definition* pChildDef = dynamic_cast<Definition*>(pRef->m_nodes.GetPrev(pos));

                if(pChildDef->IsType(type))
                {
                    if(pChildDef->IsNameUnknown()) pDef = pChildDef;
                    break;
                }
            }

            if(!pDef)
            {
                pDef = m_pnf->CreateDef(pRef, type);
            }

            if(i == j)
            {
                pDef->SetAsValue(s, v, u);
                return pDef;
            }
        }
    }

    return NULL;
}
示例#22
0
Bookmark::Definition* Bookmark::Find(BFont* font) const
{
	font_family family;
	font_style  style;
	float       size;

	font->GetFamilyAndStyle(&family, &style);
	size = font->Size();
	
	for (int i = 0; i < fDefinitions.CountItems(); i++) {
		Definition* definition = fDefinitions.ItemAt(i);
		if (definition->Matches(&family, &style, size)) {
			return definition;
		}
	}
	return NULL;
}
示例#23
0
	Definition* NodeFactory::CreateDef(Reference* pParentRef, CStringW type, CStringW name, NodePriority priority)
	{
		Definition* pDef = NULL;

		if(name.IsEmpty())
		{
			name = GenName();
		}
		else 
		{
			pDef = GetDefByName(name);

			if(pDef)
			{
				if(!pDef->m_predefined)
				{
					throw Exception(_T("redefinition of '%s' is not allowed"), CString(name));
				}

				if(!pDef->IsTypeUnknown() && !pDef->IsType(type))
				{
					throw Exception(_T("cannot redefine type of %s to %s"), CString(name), CString(type));
				}
			}
		}

		if(!pDef)
		{
			pDef = DNew Definition(this, name);

			m_nodes.SetAt(name, pDef);
			m_newnodes.AddTail(name);

			if(pParentRef)
			{
				pParentRef->AddTail(pDef);
				pDef->m_parent = pParentRef;
			}
		}

		pDef->m_type = type;
		pDef->m_priority = priority;
		pDef->m_predefined = m_predefined;

		return pDef;
	}
示例#24
0
static void writeLineNumber(CodeOutputInterface &ol,FileDef *fd,uint line)
{
  Definition *d = fd ? fd->getSourceDefinition(line) : 0;
  if (d && d->isLinkable())
  {
    g_currentDefinition=d;
    g_currentLine=line;
    MemberDef *md = fd->getSourceMember(line);
    if (md && md->isLinkable())  // link to member
    {
      if (g_currentMemberDef!=md) // new member, start search for body
      {
        g_searchForBody=TRUE;
        g_insideBody=FALSE;
        g_bracketCount=0;
      }
      g_currentMemberDef=md;
      ol.writeLineNumber(md->getReference(),
                         md->getOutputFileBase(),
                         md->anchor(),
                         line);
    }
    else // link to compound
    {
      g_currentMemberDef=0;
      ol.writeLineNumber(d->getReference(),
                         d->getOutputFileBase(),
                         d->anchor(),
                         line);
    }
  }
  else // no link
  {
    ol.writeLineNumber(0,0,0,line);
  }

  // set search page target
  if (Doxygen::searchIndex)
  {
    QCString lineAnchor;
    lineAnchor.sprintf("l%05d",line);
    ol.setCurrentDoc(fd,lineAnchor,TRUE);
  }

  //printf("writeLineNumber(%d) g_searchForBody=%d\n",line,g_searchForBody);
}
示例#25
0
void ClangParser::linkIdentifier(CodeOutputInterface &ol,FileDef *fd,
    uint &line,uint &column,const char *text,int tokenIndex)
{
  CXCursor c = p->cursors[tokenIndex];
  CXCursor r = clang_getCursorReferenced(c);
  if (!clang_equalCursors(r, c))
  {
    c=r; // link to referenced location
  }
  CXCursor t = clang_getSpecializedCursorTemplate(c);
  if (!clang_Cursor_isNull(t) && !clang_equalCursors(t,c))
  {
    c=t; // link to template 
  }
  CXString usr = clang_getCursorUSR(c);
  const char *usrStr = clang_getCString(usr);

  Definition *d = usrStr ? Doxygen::clangUsrMap->find(usrStr) : 0;
  //CXCursorKind kind = clang_getCursorKind(c);
  //if (d==0)
  //{
  //  printf("didn't find definition for '%s' usr='******' kind=%d\n",
  //      text,usrStr,kind);
  //}
  //else
  //{
  //  printf("found definition for '%s' usr='******' name='%s'\n",
  //      text,usrStr,d->name().data());
  //}
  if (d && d->isLinkable())
  {
    if (g_insideBody &&
        g_currentMemberDef && d->definitionType()==Definition::TypeMember && 
        (g_currentMemberDef!=d || g_currentLine<line)) // avoid self-reference
    {
      addDocCrossReference(g_currentMemberDef,(MemberDef*)d);
    }
    writeMultiLineCodeLink(ol,fd,line,column,d,text);
  }
  else
  {
    codifyLines(ol,fd,text,line,column);
  }
  clang_disposeString(usr);
}
示例#26
0
void PYGenerator::generate()
{
	std::string fn = gOptions.output_ + gOptions.inputFS_ + ".py";
	CodeFile f(fn);
	f.output("from bintalk import protocol_writer");
	f.output("from bintalk import protocol_reader");
	for(std::set<std::string>::iterator iter = gContext.imported_.begin();
		iter != gContext.imported_.end(); ++iter)
	{
		std::string incFilename = *iter;
		incFilename = incFilename.substr(0,incFilename.find('.'));
		f.output("from %s import *", incFilename.c_str());
	}
	for(size_t i = 0; i < gContext.definitions_.size(); i++)
	{
		Definition* definition = gContext.definitions_[i];
		if(definition->file_ != gOptions.inputFN_)
			continue;
		if (definition->getEnum())
			generateEnum(f, definition->getEnum());
		else if (definition->getStruct())
			generateStruct(f, definition->getStruct());
		else if (definition->getService())
			generateService(f, definition->getService());
	}
}
示例#27
0
	void SubtitleFile::Append(InputStream& s, float start, float stop, bool fSetTime)
	{
		Reference* pRootRef = GetRootRef();

		ParseDefs(s, pRootRef);

		CAtlList<Definition*> defs;
		GetNewDefs(defs);

		POSITION pos = defs.GetHeadPosition();
		while(pos)
		{
			Definition* pDef = defs.GetNext(pos);

			if(pDef->m_parent == pRootRef && pDef->m_type == L"subtitle" && (*pDef)[L"@"].IsValue())
			{
				m_segments.Insert(start, stop, pDef);

				if(fSetTime) 
				{
					try
					{
						Definition::Time time;
						StringMapW<float> offset;
						pDef->GetAsTime(time, offset);
						if(time.start.value == start && time.stop.value == stop)
							continue;
					}
					catch(Exception&)
					{
					}

					CStringW str;
					str.Format(L"%.3f", start);
					pDef->SetChildAsNumber(L"time.start", str, L"s");
					str.Format(L"%.3f", stop);
					pDef->SetChildAsNumber(L"time.stop", str, L"s");
				}
			}
		}

		Commit();
	}
示例#28
0
DimBounds get_stage_bounds(Function f, int stage_num, const DimBounds &pure_bounds) {
    DimBounds bounds;
    Definition def = get_stage_definition(f, stage_num);

    // Assume that the domain of the pure vars across all the update
    // definitions is the same. This may not be true and can result in
    // over estimation of the extent.
    for (const auto &b : pure_bounds) {
        bounds[b.first] = b.second;
    }

    for (const auto &rvar : def.schedule().rvars()) {
        Expr lower = SubstituteVarEstimates().mutate(rvar.min);
        Expr upper = SubstituteVarEstimates().mutate(rvar.min + rvar.extent - 1);
        bounds.emplace(rvar.var, Interval(simplify(lower),simplify(upper)));
    }

    return bounds;
}
    bool check() {
        for (const auto& topic : fBmhParser.fTopicMap) {
            Definition* topicDef = topic.second;
            if (topicDef->fParent) {
                continue;
            }
            if (!topicDef->isRoot()) {
                return fBmhParser.reportError<bool>("expected root topic");
            }
            fRoot = topicDef->asRoot();
            if (!this->checkSeeAlso()) {
                return false;
            }
            // report functions that are not covered by related hierarchy
			if (!this->checkRelatedFunctions()) {
				return false;
			}
        }
        return true;
    }
示例#30
0
double Overlap(Definition &def1, Definition &def2)
{
	int numShareWord = def1.Overlap(def2);
#ifdef I_AM_PARANOIK
	int as = def1.wordCount + def2.wordCount;
	if (!as)
		return 0;
	return numShareWord/((double)as);
#else
	return numShareWord/((double)(def1.wordCount + def2.wordCount));
#endif
}