OsmMapPtr AlphaShapeGenerator::generateMap(OsmMapPtr inputMap)
{
  boost::shared_ptr<Geometry> cutterShape = generateGeometry(inputMap);
  if (cutterShape->getArea() == 0.0)
  {
    //would rather this be thrown than a warning logged, as the warning may go unoticed by web
    //clients who are expecting the alpha shape to be generated
    throw HootException("Alpha Shape area is zero. Try increasing the buffer size and/or alpha.");
  }

  OsmMapPtr result;

  result.reset(new OsmMap(inputMap->getProjection()));
  // add the resulting alpha shape for debugging.
  GeometryConverter(result).convertGeometryToElement(cutterShape.get(), Status::Invalid, -1);

  const RelationMap& rm = result->getRelations();
  for (RelationMap::const_iterator it = rm.begin(); it != rm.end(); ++it)
  {
    Relation* r = result->getRelation(it->first).get();
    r->setTag("area", "yes");
  }

  return result;
}
示例#2
0
void Database::processRule(Rule* rule) {
    //Find the relation in the list of schemes matching the head of the predicate
    Relation* headRelation = getHeadRelation(rule);
    
    //Get the list of predicates
    std::vector<Predicate*> predicateList = rule->j;
    
    //Create new relations from each predicate
    std::vector<Relation*> relationList = getRelationList(predicateList);
    
    //Natural join the relations from the predicates
    Relation* newRelation = join(relationList);
    
    //Project on the final relation; only keep columns matching variables in the rule head
    std::vector<std::string> headVariables = getHeadVariables(rule->hpl);
    newRelation = newRelation->project(headVariables);
    
    //Find the relation in the database that matches the head of the rule
        //Already done (it's headRelation)
    
    //Rename attributes in the new relation so it matches the rule head's schema
    newRelation = renameToMatch(headRelation, newRelation, headVariables);
    
    //Union the new relation with the matching relation
    headRelation = unionWith(headRelation, newRelation);
    std::sort(headRelation->facts.begin(), headRelation->facts.end(), Relation::tupleCompare);
}
示例#3
0
void join(Relation &lhs, Relation &rhs, vector<size_t> &vars, Relation &result) {
  Relation temp;
  Relation *l, *r;
  if (lhs.size() >= rhs.size()) {
    l = &lhs;
    r = &rhs;
  } else {
    l = &rhs;
    r = &lhs;
  }
  Order order(vars, false);
  multiset<Tuple, Order> index (order);
  Relation::iterator it = r->begin();
  for (; it != r->end(); ++it) {
    index.insert(*it);
  }
  for (it = l->begin(); it != l->end(); ++it) {
    pair<multiset<Tuple, Order>::iterator,
         multiset<Tuple, Order>::iterator> rng = index.equal_range(*it);
    multiset<Tuple, Order>::iterator rit;
    for (rit = rng.first; rit != rng.second; ++rit) {
      Tuple res;
      if (!join(*it, *rit, res)) {
        cerr << "[ERROR] Two tuples that were expected to be compatible turned out not to be.  This indicates a flaw in the program logic." << endl;
      }
      temp.push_back(res);
    }    
  }
  result.swap(temp);
}
示例#4
0
Tokend::Relation *EstEIDSchema::createKeyRelation(CSSM_DB_RECORDTYPE keyType) {
    FLOG;

    Relation *rn = createStandardRelation(keyType);

    // Set up coders for key records.
    MetaRecord &mr = rn->metaRecord();
    mr.keyHandleFactory(&mEstEIDKeyHandleFactory);

    // Print name of a key might as well be the key name.
    mr.attributeCoder(kSecKeyPrintName, &mDescriptionCoder);

    // Other key values
    mr.attributeCoder(kSecKeyKeyType, &mKeyAlgorithmCoder);
    mr.attributeCoder(kSecKeyKeySizeInBits, &mKeySizeCoder);
    mr.attributeCoder(kSecKeyEffectiveKeySize, &mKeySizeCoder);

    // Key attributes
    mr.attributeCoder(kSecKeyExtractable, &mFalseCoder);
    mr.attributeCoder(kSecKeySensitive, &mTrueCoder);
    mr.attributeCoder(kSecKeyModifiable, &mFalseCoder);
    mr.attributeCoder(kSecKeyPrivate, &mTrueCoder);
    mr.attributeCoder(kSecKeyNeverExtractable, &mTrueCoder);
    mr.attributeCoder(kSecKeyAlwaysSensitive, &mTrueCoder);

    // Key usage
    mr.attributeCoder(kSecKeyEncrypt, &mFalseCoder);
    mr.attributeCoder(kSecKeyWrap, &mFalseCoder);
    mr.attributeCoder(kSecKeyVerify, &mFalseCoder);
    mr.attributeCoder(kSecKeyDerive, &mFalseCoder);
    mr.attributeCoder(kSecKeySignRecover, &mFalseCoder);
    mr.attributeCoder(kSecKeyVerifyRecover, &mFalseCoder);

    return rn;
}
Relation HTMLOutputAccessible::RelationByType(RelationType aType) const {
  Relation rel = AccessibleWrap::RelationByType(aType);
  if (aType == RelationType::CONTROLLED_BY)
    rel.AppendIter(new IDRefsIterator(mDoc, mContent, nsGkAtoms::_for));

  return rel;
}
Relation
XULGroupboxAccessible::RelationByType(PRUint32 aType)
{
    Relation rel = AccessibleWrap::RelationByType(aType);
    if (aType != nsIAccessibleRelation::RELATION_LABELLED_BY)
        return rel;

    // The label for xul:groupbox is generated from xul:label that is
    // inside the anonymous content of the xul:caption.
    // The xul:label has an accessible object but the xul:caption does not
    PRUint32 childCount = ChildCount();
    for (PRUint32 childIdx = 0; childIdx < childCount; childIdx++) {
        Accessible* childAcc = GetChildAt(childIdx);
        if (childAcc->Role() == roles::LABEL) {
            // Ensure that it's our label
            Relation reverseRel =
                childAcc->RelationByType(nsIAccessibleRelation::RELATION_LABEL_FOR);
            Accessible* testGroupbox = nsnull;
            while ((testGroupbox = reverseRel.Next()))
                if (testGroupbox == this) {
                    // The <label> points back to this groupbox
                    rel.AppendTarget(childAcc);
                }
        }
    }

    return rel;
}
示例#7
0
void HasTagSelector::matchRelation(RelId relID, const shared_ptr<TileIdentifier>& ti, RenderAttributes* attributes) const {
	Relation* relation = geodata->getRelation(relID);

	auto& map = relation->getTags();
	if (map.find(tag) != map.end()) {
		next->matchRelation(relID, ti, attributes);
	}
}
示例#8
0
void print_relations(const Relation& relations)
{
    for (Relation::const_iterator rela_iter = relations.begin();
            rela_iter != relations.end(); rela_iter++) {
        copy(rela_iter->begin(), rela_iter->end(), ostream_iterator<int>(cout, " "));
        cout << endl;
    }
}
/*--------------------------------------------------
 * A query starts with a relation's name, followed 
 * by the relation assignment '<-' and an expression. 
 *--------------------------------------------------*/
Engine Evaluator::evalQuery() {
	string relationName = evalRelationName(tokens[cur]);

	// Check if relation-name is valid
	if(relationName.empty()) {
		return engine;
	} else {
		// Check if pointer can move
		if(isEndOfLine()) {
			printIncompleteError("query", "Missing <-");
			return engine;
		} else {
			// Move pointer to next token: <-
			cur++;
			string arrowCheck = tokens[cur];
			
			if(arrowCheck.compare("<-") == 0) {
				// Check if pointer can move
				if(isEndOfLine()) {
					printIncompleteError("query", "Missing expression");
					return engine;
				} else {
					// Move pointer to next token: expression
					cur++;
					
					Relation rel = evalExpression();
//					rel.printTuples();
					cur--;
					// Check if relation is valid
					if(rel.isVoid()) {
						return engine;
					} else {
						// Check if pointer can move
						if(isEndOfLine()) {
							printIncompleteError("query", "Missing ;");
							return engine;
						} else {
							// Move pointer to next token: ;
							cur++;
							string semiCheck = tokens[cur];
							//if(semiCheck.compare(";") == 0) {
								rel.setName(relationName);
								cout << rel.getName() << endl;
								//I changed this
								//rel.printTuples();								
								engine.addRelation(rel);
								//engine.show(relationName);
								//engine.setRelation(relationName, rel);

							//} else printInvalidError("open", ";", semiCheck);
						}
					}
				}
			} else printInvalidError("query", "<-", arrowCheck);		
		}
	}
	return engine;
}
示例#10
0
Relation* RelationList::findRelation(Node* node0, Node* node1){
	for (int i=0; i<getNumNodes(); i++) {
		Relation* relation = (Relation*)getNodeAt(i);
		if ( (relation->getNode0()==node0 && relation->getNode1()==node1) || (relation->getNode0()==node1 && relation->getNode1()==node0) ) {
			return relation;
		}
	}
	return NULL;
}
示例#11
0
void Interpretter::evalRules(vector <Rule>& rulelist) {

    for (Rule rule : rulelist) {
        cout << rule.toString();
        output += rule.toString();
        
        //get the first rule, then iterate thru the rest, adding to the new "joined" Relation
        Relation joined = db[rule.getPredicates()[0].getID()];
        
        // set a joined scheme, based on predicate[0]'s params. And give it to me in tuple format
        joined.redoScheme(rule.getPredicates()[0].getParams());
        if (rulelist.size() > 1) {
            vector <Relation> processedPreds;
            if (rule.getPredicates().size() > 1) {
                
                //for each Predicate (after the first) in the rule
                for (int i = 1; i < rule.getPredicates().size(); i++) {
                    Relation r = db[rule.getPredicates()[i].getID()];
                    Tuple predT = predToTuple(rule.getPredicates()[i]);
                    
                    Relation selected = r.select(predT);
                    //output += selected.toString();
                    
                    //Relation projected = selected.project(predT);
                    //output += projected.toString();
                    
                    Relation renamed = selected.rename(predT);
                    processedPreds.push_back(renamed);
                    joined = joined.join(renamed);
                }
            }
        }

        Tuple renameScheme;
        //cout << "rule.getName() = " << rule.getName() << endl;
        for (auto item : rule.getParams()) {
            renameScheme.push_back(item.getVal());
        }
        //cout << "joined" << joined.toString();
        Relation projectRule = joined.project2(renameScheme); //project with the original columns
        //Relation renameRule = projectRule.rename(renameScheme); // use the original scheme
        //cout << renameRule.toString();
        int prevSize = db[rule.getName()].getRelSize();
        for (auto tuple : projectRule.getTuples()) {

            db[rule.getName()].add(tuple);

            //if it actually added
            if (db[rule.getName()].getRelSize() > prevSize) {
                output += db[rule.getName()].tupleToString(tuple);
                prevSize = db[rule.getName()].getRelSize();
                addedTuples++;
            }
        }
        
    }
}
示例#12
0
文件: Relation.cpp 项目: raull/CS236
string Relation::parse(Queries query){
	Relation editedRelation = *this;

	editedRelation = rename(query.getTuple(), editedRelation);
	editedRelation = select(query.getTuple(), editedRelation);
	editedRelation = project(query.getTuple(), editedRelation);

	return editedRelation.toFinalString(query);
}
Relation
nsHTMLOutputAccessible::RelationByType(PRUint32 aType)
{
  Relation rel = nsAccessibleWrap::RelationByType(aType);
  if (aType == nsIAccessibleRelation::RELATION_CONTROLLED_BY)
    rel.AppendIter(new IDRefsIterator(mDoc, mContent, nsGkAtoms::_for));

  return rel;
}
Relation
HTMLFigureAccessible::RelationByType(RelationType aType)
{
  Relation rel = HyperTextAccessibleWrap::RelationByType(aType);
  if (aType == RelationType::LABELLED_BY)
    rel.AppendTarget(mDoc, Caption());

  return rel;
}
示例#15
0
Relation
HTMLTableAccessible::RelationByType(RelationType aType)
{
  Relation rel = AccessibleWrap::RelationByType(aType);
  if (aType == RelationType::LABELLED_BY)
    rel.AppendTarget(Caption());

  return rel;
}
Relation
nsHTMLTableAccessible::RelationByType(PRUint32 aType)
{
  Relation rel = nsAccessibleWrap::RelationByType(aType);
  if (aType == nsIAccessibleRelation::RELATION_LABELLED_BY)
    rel.AppendTarget(Caption());

  return rel;
}
示例#17
0
Relation
HTMLCaptionAccessible::RelationByType(RelationType aType)
{
  Relation rel = HyperTextAccessible::RelationByType(aType);
  if (aType == RelationType::LABEL_FOR)
    rel.AppendTarget(Parent());

  return rel;
}
示例#18
0
void TagMatchesSelector::matchRelation(RelId relID, const shared_ptr<TileIdentifier>& ti, RenderAttributes* attributes) const {
	Relation* relation = geodata->getRelation(relID);
	auto entry = relation->getTags().find(tag);
	if (entry != relation->getTags().end()) {
		if (boost::regex_match(entry->second.str(), expression)) {
			next->matchRelation(relID, ti, attributes);
		}
	}
}
示例#19
0
void BulkData::declare_relation( Entity & e_from ,
                                     Entity & e_to ,
                                     const unsigned identifier ,
                                     const unsigned kind )
{
  static const char method[] = "phdmesh::BulkData::declare_relation" ;

  if ( in_closure( e_to , e_from ) ) {
    std::ostringstream msg ;
    print_declare_relation( msg , method , e_from , e_to , identifier , kind );
    msg << " FAILED DUE TO CIRCULAR CLOSURE." ;
    throw std::runtime_error( msg.str() );
  }

  {
    const Relation forward( e_to , identifier , kind , false );
    const std::vector<Relation>::iterator e = e_from.m_relation.end();
          std::vector<Relation>::iterator i = e_from.m_relation.begin();

    i = std::lower_bound( i , e , forward , LessRelation() );

    if ( e == i || forward != *i ) { // Not a duplicate

      if ( e != i && forward.attribute() == i->attribute() ) {
        std::ostringstream msg ;
        print_declare_relation( msg, method, e_from, e_to, identifier, kind );
        msg << " FAILED, ALREADY HAS THIS RELATION TO " ;
        print_entity_key( msg , i->entity()->key() );
        throw std::runtime_error(msg.str());
      }

      e_from.m_relation.insert( i , forward );
    }
  }

  {
    const Relation converse( e_from , identifier , kind , true );
    const std::vector<Relation>::iterator e = e_to.m_relation.end();
          std::vector<Relation>::iterator i = e_to.m_relation.begin();

    i = std::lower_bound( i , e , converse , LessRelation() );

    if ( e == i || converse != *i ) { // Not a duplicate
      e_to.m_relation.insert( i , converse );
    }
  }

  {
    PartSet add , del ;

    deduce_part_relations( e_from , e_to , identifier , kind , add );

    internal_change_entity_parts( e_to , add , del );
  }

  set_field_relations( e_from , e_to , identifier , kind );
}
Relation
HTMLFigureAccessible::RelationByType(uint32_t aType)
{
  Relation rel = HyperTextAccessibleWrap::RelationByType(aType);
  if (aType == nsIAccessibleRelation::RELATION_LABELLED_BY)
    rel.AppendTarget(mDoc, Caption());

  return rel;
}
Relation HTMLLabelAccessible::RelationByType(RelationType aType) const {
  Relation rel = AccessibleWrap::RelationByType(aType);
  if (aType == RelationType::LABEL_FOR) {
    dom::HTMLLabelElement* label = dom::HTMLLabelElement::FromNode(mContent);
    rel.AppendTarget(mDoc, label->GetControl());
  }

  return rel;
}
Relation
nsHTMLCaptionAccessible::RelationByType(PRUint32 aType)
{
  Relation rel = nsHyperTextAccessible::RelationByType(aType);
  if (aType == nsIAccessibleRelation::RELATION_LABEL_FOR)
    rel.AppendTarget(Parent());

  return rel;
}
示例#23
0
void PropertiesDock::cleanUpUi()
{
    if (NowShowing == RelationUiShowing)
    {
        RelationUi.MembersView->setModel(0);
        Relation* R = dynamic_cast<Relation*>(FullSelection[0]);
        R->releaseMemberModel();
    }
}
Relation
HTMLGroupboxAccessible::RelationByType(RelationType aType)
{
  Relation rel = HyperTextAccessibleWrap::RelationByType(aType);
    // No override for label, so use <legend> for this <fieldset>
  if (aType == RelationType::LABELLED_BY)
    rel.AppendTarget(mDoc, GetLegend());

  return rel;
}
示例#25
0
void Database::parseSchemes()
{
	Relation rel;
	for (int i = 0; i < Schemes.size(); i++){
		rel.setName(Schemes[i].getData());
		setRelationScheme(rel, i);
		relations.insert(pair<string, Relation>(rel.getName(), rel));
		rel.clearTupScheme();
	}
}
示例#26
0
RelationList* RelationList::findRelations(Node* node){
	RelationList* filteredRelations=new RelationList();
	for (int i=0; i<getNumNodes(); i++) {
		Relation* relation = (Relation*)getNodeAt(i);
		if ( relation->getNode0()==node || relation->getNode1()==node ) {
			filteredRelations->addRelation(relation);
		}
	}
	return filteredRelations;
}
示例#27
0
void Relations::load(const VariantMap &stream)
{
  for( auto item : stream )
  {
    Relation r;
    r.load( item.second.toMap() );

    (*this)[ item.first ] = r;
  }
}
Relation HTMLLegendAccessible::RelationByType(RelationType aType) const {
  Relation rel = HyperTextAccessibleWrap::RelationByType(aType);
  if (aType != RelationType::LABEL_FOR) return rel;

  Accessible* groupbox = Parent();
  if (groupbox && groupbox->Role() == roles::GROUPING)
    rel.AppendTarget(groupbox);

  return rel;
}
Relation
nsHTMLGroupboxAccessible::RelationByType(PRUint32 aType)
{
  Relation rel = nsHyperTextAccessibleWrap::RelationByType(aType);
    // No override for label, so use <legend> for this <fieldset>
  if (aType == nsIAccessibleRelation::RELATION_LABELLED_BY)
    rel.AppendTarget(GetLegend());

  return rel;
}
示例#30
0
static bool isChildOfRelation(Feature *mapFeature)
{
    for (int i=0; i<mapFeature->sizeParents(); i++)
    {
        Relation * rel = CAST_RELATION(mapFeature->getParent(i));
        if (rel && !rel->isDeleted())
            return true;
    }

    return false;
}