int TestGETLINKS2() {
  START_TEST_CASE;
  
  char *query = "liBaTion"; // The query we want to test with.
  
  int result = GetLinks(query, ptr);
  SHOULD_BE(temp_list == NULL);
  SHOULD_BE(final_list != NULL);
  SHOULD_BE(result == 1);
  
  DocumentNode *cpy = final_list;
  
  char *query2 = "libation";
  GetLinks(query2, ptr);
  SHOULD_BE(final_list != NULL);
  
  DocumentNode *ptr, *ptr2;
  for (ptr = cpy; ptr != NULL; ptr = ptr->next) {
  	for (ptr2 = final_list; ptr2 != NULL; ptr2 = ptr2->next) {
  		SHOULD_BE(ptr->doc_id == ptr2->doc_id);
  		SHOULD_BE(ptr->freq == ptr2->freq);
  	}
  }
  
  // Cleanup.
  FreeList(1);
  final_list = cpy;
  FreeList(1);
  
  END_TEST_CASE;
}
Beispiel #2
0
//_____________________________________________________________________________
Bool_t KVDBKey::LinkTo(KVDBRecord* rec, Bool_t linkback)
{
// This function adds a record to the list of cross-references
// if fIsUnique is kTRUE we check if there is already an object with the same name:
//    if so we return kFALSE otherwise the record is added and kTRUE is returned.
// if fSingle is kTRUE the list can handle only one object:
//    if the list is empty the record is added and kTRUE is returned, otherwise kFALSE.

   // check if more than one object is allowed
   if (fSingle && (GetLinks()->GetSize() > 0) && (GetLinks()->First())) {
      Warning("LinkTo(KVDBRecord*)",
              "%s : Only one cross-reference allowed.\nCurrent cross-reference is:%s\nCan't add new record \"%s\" in list",
              GetName(), GetLinks()->First()->GetName(), rec->GetName());
      return kFALSE;
   }
   // check if identical names are allowed
   if (fIsUnique) {
      if (fLinks->FindObject(rec->GetName())) {
         Warning("LinkTo(KVDBRecord*)",
                 "%s : Cross-references must have different names.\nA record named %s already exists.\nCan't add new record \"%s\" in list",
                 GetName(), rec->GetName(), rec->GetName());
         return kFALSE;
      }
   }
   AddLink(rec);

   if (linkback) {
      //if linkback is kTRUE then a mirror link to this record will be made in record "rec"
      //if a key with the same name as the table containing the current record is found
      //in the record to link , then this key is linked back to the current record.
      //if no key is found, one will be created, and then the linkback performed.

      //check parent is set
      if (!GetParent()) {
         Error("LinkTo", "Parent table not set for key %s", GetName());
         return kFALSE;
      }
      const Char_t* table_name = GetParent()->GetTable()->GetName();

      KVDBKey* key = rec->GetKey(table_name);
      if (!key)
         key = rec->AddKey(table_name, GetParent()->GetName());
      key->LinkTo(GetParent(), kFALSE); //linkback=kFALSE otherwise infinite circular linkage results !!!
   }
   return kTRUE;
}
int TestGETLINKS3() {
  START_TEST_CASE;
    
  char *query = "bumblearhr"; // The query we want to test with.
  
  int result = GetLinks(query, ptr);
  SHOULD_BE(temp_list == NULL);
  SHOULD_BE(final_list == NULL);
  SHOULD_BE(result == 1);
  END_TEST_CASE;
}
Beispiel #4
0
	void Page::ProcessLinks(OutputDev *pOut, Catalog *pCatalog)
	{
		Links *pLinks = GetLinks(pCatalog);
		if (pLinks)
		{
			for (int nIndex = 0; nIndex < pLinks->GetLinksCount(); ++nIndex)
			{
				pOut->ProcessLink(pLinks->GetLink(nIndex), pCatalog);
			}
			delete pLinks;
		}
	}
int TestGETLINKS6() {
  START_TEST_CASE;
  
  char *query = "squash whale"; // The query we want to test with.
  
  int result = GetLinks(query, ptr);
  SHOULD_BE(temp_list == NULL);
  SHOULD_BE(final_list != NULL);
  SHOULD_BE(final_list->doc_id == 1130);
  SHOULD_BE(final_list->next == NULL);
  SHOULD_BE(result == 1);
  
  FreeList(1);
  END_TEST_CASE;
}
int TestGETLINKS1() {
  START_TEST_CASE;
  
  char *query = "AND life"; // The query we want to test with.
  
  int result = GetLinks(query, ptr);
  SHOULD_BE(temp_list == NULL);
  SHOULD_BE(final_list == NULL);
  SHOULD_BE(result == 0);
  
  // Cleanup.
  FreeList(1);
  
  
  END_TEST_CASE;
}
int TestGETLINKS4() {
  START_TEST_CASE;
  
  char *query = "libation OR hindrance"; // The query we want to test with.
  
  int result = GetLinks(query, ptr);
  SHOULD_BE(temp_list == NULL);
  SHOULD_BE(final_list != NULL);
  
  DocumentNode *ptr;
  int i = 0;
  int arr[3] = {1467, 259, 891};
  for (ptr = final_list; ptr != NULL; ptr = ptr->next) {
  	SHOULD_BE(ptr->doc_id == arr[i] && ptr->freq == 1);
  	i++;
  }
  
  SHOULD_BE(result == 1);
  
  FreeList(1);
  END_TEST_CASE;
}
Beispiel #8
0
int main (int argc, char *argv[]) {
	
	// Check arguments
	
	// Check that there are two arguments passed.
	if (argc != 3) {
		printf("Please input exactly two arguments.\n");
		printf("Usage: ./query [INDEX_FILE] [HTML_DIRECTORY]\n");
		return 1;
	}
	
	// Check that the index file exists.
	if (!IsFile(argv[1])) {
		printf("Please input an existing [INDEX_FILE].\n");
		return 1;
	} 
	
	// Since the index file is valid, copy file name to file.
	file = calloc(1, strlen(argv[1]) + 1);
	strcpy(file, argv[1]);
	
	// Check that the html directory exists.
	if (!IsDir(argv[2])) {
		printf("Please input an existing [HTML_DIRECTORY].\n");
		return 1;
	}
	
	// Since the directory is valid, copy path to dir_path.
	dir_path = calloc(1, strlen(argv[2]) + 1);
	strcpy(dir_path, argv[2]);

	
	// Declare variables.
	HashTable Index;
	HashTable *ptr;
	char *query;
	
	// Load and recreate an InvertedIndex from index file.
	InitializeHashTable(&Index);
	ptr = ReadFile(file, &Index);
	
	printf("Query:> ");
	
	// Receive user queries from input.
	while ((query = (char *)calloc(1, MAX)) && fgets(query, MAX, stdin)) {
		
		// Check query line.
		
		// If the query line is empty, ask for input again.
		if (strcmp(query, "\n") == 0) {
			printf("Please input words.\n\n");
			printf("Query:> ");
			free(query);
			continue;
		}
		
		// Check that only ASCII characters, or whitespace in between is passed.
		int i;
		for (i=0; i<strlen(query); i++) {
			if (!isalpha(query[i]) && !isspace(query[i])) {
				break;				
			}
		}
		if (i != strlen(query)) {
			printf("Please input only ASCII characters, whitespace, or logical operators.\n\n");
			printf("Query:> ");
			free(query);
			continue;
		}
		
		// Check that at least one word is passed, ie the query is not just whitespace.
		for (i=0; i<strlen(query); i++) {
			if (!isspace(query[i])) {
				break;
			}
		}
		if (i == strlen(query)) {
			printf("Please input only ASCII characters, whitespace, or logical operators.\n\n");
			printf("Query:> ");
			free(query);
			continue;
		}
		
		// Check that no two successive logical operators are passed.
		if (strstr(query, "AND OR") || strstr(query, "AND AND") || strstr(query, "OR AND") || strstr(query, "OR OR")) {
			printf("Please input a valid query line.\n\n");
			printf("Query:> ");
			free(query);
			continue;
		}
		
		
		// Get the list of DocumentNodes containing the query.
		if (!GetLinks(query, ptr)) {
			printf("Please input a valid query line.\n\n");
			printf("Query:> ");
			
			// Cleanup.
			free(query);
			FreeList(0);
			FreeList(1);
			
			continue;
		}
		
		// Sort only if there are two are more documents in the list.
		if (final_list != NULL && final_list->next != NULL) {
			Sort(); // Sort by rank.
		}
		
		
		// Display results to stdout.
		if (!Display()) {
			printf("Error retrieving url from directory. Please check HTML_DIRECTORY.\n\n");
			// Cleanup.
			FreeList(0);
			FreeList(1);
			break;
		}
		printf("\n\n");
		printf("Query:> ");
		
		// Cleanup.
		FreeList(1);
		free(query);
	}
	
	// Cleanup.
	free(query);
	CleanHashTable(ptr);
	FreeHashTable(ptr);
	free(file);
	free(dir_path);
	
	return 0;
}