Exemplo n.º 1
0
void* createForum(void *arg){

	Graph* currentG;
	Edge* current;
	Node* n;
	create_args* args = (create_args*)arg;
	Forum* forum = args->forum;
	Graph* gforum = args->gforum;
	Graph* graph = args->g;
	Node* node = lookupNode(forum->id,gforum);
	
	//printf("%s\n",forum->name);
	currentG = createGraph(5, 10 , forum->name);
	currentG->next = NULL;
		
	insertEdgeProperty(currentG,"knows");
	if ( node->edges==NULL || node->edges->size < 0)
		current = NULL;
	else
		current = node->edges->edge[0];
		
	while (current!=NULL){
		n = setNodeProperties(current->endID,NULL,NULL,0);
		
		insertNode(n,currentG);
		current = current->next;
	}
	find_copy_edges(graph,currentG,"knows","knows");
	
	pthread_exit(currentG);
}
Exemplo n.º 2
0
/* Creates a graph based on schema's relation person_knows_person
 * bucketsNumber: size of hashtable
 * bucketSize: size of cells in a bucket
 * loads also from data file as attributes anything might be useful
 * mustn't save any query/metric estimation
 * return value: the loaded graph*/
Graph* loadEntityGraph(char* filename, char* name,int bucketsNumber, int bucketSize,int number_of_properties,const int* type){
  	FILE *from = fopen(filename,"r");
  
    size_t line_size=120; 
    char* line=NULL,*temp;
    char* stringID;
    int i;
    Graph* current;
    Node* node;
    int id;
    char **property;
    property = (char**)malloc(sizeof(char*)*number_of_properties);

    int startid;
    
    
    int endid;
    Graph* g= createGraph(bucketsNumber, bucketSize,name);
    current = g;
    getline(&line,&line_size,from);
    free(line);
    line=NULL;
    while (!feof(from)){
    	getline(&line,&line_size,from);
    	
    	temp = line;
    	stringID = strtok(line,"|\n");
    	if (stringID!=NULL){
			id = atoi(stringID);
			for (i=0;i<number_of_properties;i++){
				property[i] =  strtok(NULL,"|\n");
			}
			
			node = setNodeProperties(id,property,type,number_of_properties);

			if (insertNode(node,g)==-1)
				destroyNode(node);        
        }
		free(line);
	   	line=NULL;     
        
        
    }	
 	free(property);
    fclose(from);
    



    
  return g;
}
	ImpNode* SceneGraphCreator::importInstance( const COLLADAFW::Node* node, INode* parentINode )
	{
		const COLLADAFW::PointerArray<Instance>& instances = (node->*getInstances)();
		if ( instances.getCount() != 1 )
			return 0;

		ImpNode* newImportNode = getMaxImportInterface()->CreateNode();
		setNodeProperties(node, newImportNode);
		INode* newNode = newImportNode->GetINode();

		Instance* instance = instances[0];
		const COLLADAFW::UniqueId& uniqueId = instance->getInstanciatedObjectId();

		Object* object = getObjectByUniqueId(uniqueId);
		if ( object )
		{
			newImportNode->Reference(object);
			const String& objectName = getObjectNameByObject(object);

			if ( node->getName().empty() && !objectName.empty() )
			{
#ifdef UNICODE
				WideString wideObjectName = COLLADABU::StringUtils::toWideString(objectName.c_str());
				newImportNode->SetName( wideObjectName.c_str() );
#else
				newImportNode->SetName( objectName.c_str() );
#endif
			}
		}
		else
		{
			newImportNode->Reference( getDummyObject() );
		}

		const COLLADAFW::UniqueId& instanceGeometryUniqueId = instance->getInstanciatedObjectId();
		// Store mapping between unique ids and nodes referencing the corresponding object.
		// Used to clone nodes
		addObjectINodeUniqueIdPair(newNode, instanceGeometryUniqueId);
		// Used to resolve instancing of objects
		addUniqueIdObjectINodePair(instanceGeometryUniqueId, newNode);
		parentINode->AttachChild(newNode, FALSE);

		// post process the creation
		if ( postProcess )
			(this->*postProcess)(newNode, instance);

		return newImportNode;
	}
Exemplo n.º 4
0
//Eisagwgh susxetisewn
void loadRelationship(char* filename,Graph* A, Graph *B,char* relationship,int number_of_properties,const int* type,int option){
	
    FILE* from = fopen(filename,"r");
    char* line=NULL;
    int line_size=50;
    int startid,endid;
    int i;
    int line_len;
    Edge* edge;
    char* stringID;
    Node* node;
    char** property;
    property = (char**)malloc(sizeof(char*)*number_of_properties);
    if (A!=NULL)
		insertEdgeProperty(A,relationship);
	if (B!=A && B!=NULL)
   		insertEdgeProperty(B,relationship);

 
	getline(&line,&line_size,from); 
	free(line);
	line = NULL;
    while (!feof(from)){
    	line_len  = getline(&line,&line_size,from);
		
    	if (line_len == -1){

			free(line);
			line=NULL;
			continue;
		}
		
    	stringID = strtok(line,"|");

    	if (stringID==NULL){
			free(line);
			line = NULL;
			continue;
		}   	
    	startid = atoi(stringID);
    	stringID = strtok(NULL,"|\n");
	
    	if (stringID==NULL){
			free(line);
			line = NULL;
			continue;
		}
		endid = atoi(stringID);
		//An dn uparxei to startID h to endID pame sthn epomenh grammh

    	for (i=0;i<number_of_properties;i++){
    		property[i] =  strtok(NULL,"|\n");
    	}
    	//An to option=1 tote ama oi susxetiseis einai metaxu 2 komvwn (an dn uparxoun tous prosthetw)
    	//Gia paradeigma sta posts an dn uparxoun ta posts pou kapios exei kanei like/replie ta prosthetw
    	if (option==1){
			if (A!=NULL && lookupNode(startid,A)==NULL){
				node = setNodeProperties(startid,NULL,NULL,0);
				insertNode(node,A);
			}
			if (A!=B && B!=NULL && lookupNode(endid,B)==NULL)	{
				node = setNodeProperties(endid,NULL,NULL,0);
				insertNode(node,B);
			}
		}
    	if (A!=NULL && lookupNode(startid,A)!=NULL){
				edge = setEdgeProperties(startid,endid,property,type,number_of_properties);
				find_insertEdge(startid,edge,A,relationship);			
			
		}
		if (A!=B && B!=NULL && lookupNode(endid,B)!=NULL){
				edge = setEdgeProperties(endid,startid,property,type,number_of_properties);
				find_insertEdge(endid,edge,B,relationship); 			
			
		}
 
    	free(line);
    	line=NULL;
    
    }	

    free(property);
    fclose(from); 




}
	//------------------------------
	ImpNode* SceneGraphCreator::importNode( const COLLADAFW::Node* node, INode* parentINode )
	{
		bool singleInstance = (node->getInstanceGeometries().getCount() +
							   node->getInstanceControllers().getCount() +
			                   node->getInstanceCameras().getCount() +
							   node->getInstanceLights().getCount() ) == 1;
		ImpNode* newImportNode = 0;
		const COLLADAFW::UniqueId& nodeUniqueId = node->getUniqueId();

		if ( !singleInstance )
		{
			newImportNode = getMaxImportInterface()->CreateNode();

			setNodeProperties(node, newImportNode);
			getMaxImportInterface()->AddNodeToScene(newImportNode);

			RefResult res = newImportNode->Reference(getDummyObject());
			if ( node->getType() == COLLADAFW::Node::JOINT )
			{
				newImportNode->GetINode()->ShowBone(1);
			}

			importInstanceGeometries(node->getInstanceGeometries(), newImportNode);
			importInstanceControllers(node->getInstanceControllers(), newImportNode);
			importInstanceCameras(node->getInstanceCameras(), newImportNode);
			importInstanceLights(node->getInstanceLights(), newImportNode);
		}
		else
		{
			newImportNode = importInstanceGeometry( node, parentINode );

			if ( !newImportNode )
				newImportNode = importInstanceController( node, parentINode );

			if ( !newImportNode )
				newImportNode = importInstanceCamera( node, parentINode );

			if ( !newImportNode )
				newImportNode = importInstanceLight( node, parentINode );

			assert(newImportNode);
		}

		INode* childNode = newImportNode->GetINode();
		importNodes(node->getChildNodes(), childNode);

		// Append all nodes that are referenced by this node.
		importInstanceNodes(node->getInstanceNodes(), newImportNode);

		/** Store the unique id of the created node, to resolve references, when ever necessary.*/ 
		addUniqueIdINodePair( nodeUniqueId, newImportNode->GetINode());

		parentINode->AttachChild(childNode, FALSE);

#if 0
		/* if there are nodes that reference the just created node, clone this node
		and append it to the referencing node.*/
		ImpNode* referencingImpNode = 0;
		while ( referencingImpNode = getReferencingImpNodesByUniqueId(nodeUniqueId) )
		{
			removeUniqueIdReferencingImpNodePair( nodeUniqueId, referencingImpNode);
			recursivelyCloneINode( referencingImpNode, newImportNode->GetINode() );
		}
#endif
		return newImportNode;
	}