feature_line_t read() {
   if (at_end) {
     assert(0);
   }
   feature_line_t temp = feature_line;
   read_feature();
   return temp;
 }
  feature_file_reader_t(std::string p_filename) :
              filename(p_filename),
              in(filename.c_str()),
              feature_line("","",""),
              at_end(false) {

    // see that the file opened
    if (!in.is_open()) {
      std::cout << "Cannot open " << filename << ": " << strerror(errno) << "\n";
      exit(1);
    }

    // read the first feature
    read_feature();
  }
Example #3
0
bool feature_vector::read_features( std::vector<string > *fnames ) {

  string mn = "read_features:";
  bool res = true;
  cout<<cn<<mn<<" Reading features ... "<<endl;

  // decide what we are reading features from. Allow explicit pass by parameter.
  std::vector<string > feature_files = feature_fnames; //default to global but allow user to pass explicit features;
  if( fnames != NULL ) feature_files = *fnames;
 

  // read each feature
  for( unsigned int i = 0; i < feature_files.size(); i++ ) {
    read_feature( feature_files.at(i) );
  }

  
  cout<<cn<<mn<<" Finished reading features."<<endl;
  
  return res;
}
Example #4
0
static s_hash_table *read_item_contents(SEbmlRead *ebmlReader, s_erc *error)
{
	s_hash_table *items_content_table = NULL;
	s_items_content_container *ic = NULL;
	uint32 *item_content_id = NULL;
	uint32 id;
	s_bool container_exhausted;


	S_CLR_ERR(error);

	/* read S_UTT_EBML_ITEMS_CONTENTS container */
	id = S_EBMLREAD_CALL(ebmlReader, container)(ebmlReader, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "read_item_contents",
				  "ebmlRead method \"container\" failed"))
		goto quit_error;

	/* 2^9 = 512 item contents for a start */
	items_content_table = s_hash_table_new(&items_content_table_free_fp, 9, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "read_item_contents",
				  "Call to \"s_hash_table_new\" failed"))
		goto quit_error;

	while (1)
	{
		container_exhausted = S_EBMLREAD_CALL(ebmlReader, container_at_end)(ebmlReader, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "read_item_contents",
					  "ebmlRead method \"container_at_end\" failed"))
			goto quit_error;

		if (container_exhausted)
			break;

		/* peek id  */
		id = S_EBMLREAD_CALL(ebmlReader, peek_id)(ebmlReader, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "read_item_contents",
					  "ebmlRead method \"peek_id\" failed"))
			goto quit_error;

		switch(id)
		{
		case S_UTT_EBML_ITEMS_CONTENT_ID:
		{
			item_content_id = S_MALLOC(uint32, 1);
			if (item_content_id == NULL)
			{
				S_FTL_ERR(error, S_MEMERROR,
						  "read_item_contents",
						  "Failed to allocate memory for 'uint32' object");
				goto quit_error;
			}

			*item_content_id = S_EBMLREAD_CALL(ebmlReader, read_uint)(ebmlReader, &id, error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "read_item_contents",
						  "ebmlRead method \"read_uint\" failed"))
				goto quit_error;

			/* make new item contents container */
			ic = S_CALLOC(s_items_content_container, 1);
			if (ic == NULL)
			{
				S_FTL_ERR(error, S_MEMERROR,
						  "read_item_contents",
						  "Failed to allocate memory for 's_items_content_container' object");
				goto quit_error;
			}

			/* create a new item contents */
			ic->content =  S_NEW(SItmContent, error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "read_item_contents",
						  "Failed to create new item content"))
				goto quit_error;

			break;
		}
		case S_UTT_EBML_ITEMS_CONTENT_FEATURES:
		{
			/* read S_UTT_EBML_ITEMS_CONTENT_FEATURES container */
			id = S_EBMLREAD_CALL(ebmlReader, container)(ebmlReader, error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "read_item_contents",
						  "ebmlRead method \"container\" failed"))
				goto quit_error;

			while (1)
			{
				container_exhausted = S_EBMLREAD_CALL(ebmlReader, container_at_end)(ebmlReader, error);
				if (S_CHK_ERR(error, S_CONTERR,
							  "read_item_contents",
							  "ebmlRead method \"container_at_end\" failed"))
					goto quit_error;

				if (container_exhausted)
				{
					/* add item contents container to hash table */
					s_hash_table_add(items_content_table, (void*)item_content_id,
									 sizeof(uint32), ic, error);
					if (S_CHK_ERR(error, S_CONTERR,
								  "read_item_contents",
								  "Call to \"s_hash_table_add\" failed"))
						goto quit_error;

					item_content_id = NULL;
					ic = NULL;
					break; /* we are finished reading the item content
							* features */
				}

				/* peek id for item content feature elements */
				id = S_EBMLREAD_CALL(ebmlReader, peek_id)(ebmlReader, error);
				if (S_CHK_ERR(error, S_CONTERR,
							  "read_item_contents",
							  "ebmlRead method \"peek_id\" failed"))
					goto quit_error;

				switch(id)
				{
				case S_UTT_EBML_ITEMS_CONTENT_FEAT_NAME:
				{
					char *feat_name;
					SObject *featObject;


					/* feature elements are ordered (feat name, feat object),
					 * so we do it in one go
					 */
					read_feature(ebmlReader,
								 &feat_name, S_UTT_EBML_ITEMS_CONTENT_FEAT_NAME,
								 &featObject, S_UTT_EBML_ITEMS_CONTENT_FEAT_OBJECT,
								 error);
					if (S_CHK_ERR(error, S_CONTERR,
								  "read_item_contents",
								  "Call to \"read_feature\" failed"))
						goto quit_error;

					/* set item content feature */
					SMapSetObject(ic->content->features, feat_name, featObject, error);
					if (S_CHK_ERR(error, S_CONTERR,
								  "read_item_contents",
								  "Call to \"SMapSetObject\" failed"))
						goto quit_error;

					/* feat name is copied */
					S_FREE(feat_name); /* sets to NULL */
					featObject = NULL;
					break;
				}
				default:
					/* unknown elements, skip */
					S_WARNING(S_FAILURE,
							  "read_item_contents",
							  "Skipping element with unknown id '0x%x'",
							  id);

					S_EBMLREAD_CALL(ebmlReader, element_skip)(ebmlReader, error);
					if (S_CHK_ERR(error, S_CONTERR,
								  "read_item_contents",
								  "ebmlRead method \"element_skip\" failed"))
						goto quit_error;
				}
			}
			break;
		}
		default:
			/* unknown elements, skip */
			S_WARNING(S_FAILURE,
					  "read_item_contents",
					  "Skipping element with unknown id '0x%x'",
					  id);

			S_EBMLREAD_CALL(ebmlReader, element_skip)(ebmlReader, error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "read_item_contents",
						  "ebmlRead method \"element_skip\" failed"))
				goto quit_error;
		}
	}

	/* here everything went OK */
	return items_content_table;

	/* errors here, clean up code */
quit_error:
	if (ic != NULL)
	{
		if (ic->content != NULL)
			S_FORCE_DELETE(ic->content, "read_item_contents", error);
		S_FREE(ic);
	}

	if (items_content_table != NULL)
	{
		s_erc local_err = S_SUCCESS;

		s_hash_table_delete(items_content_table, &local_err);
		S_CHK_ERR(&local_err, S_CONTERR,
				  "read_item_contents",
				  "Call to \"s_hash_table_delete\" failed");
	}

	if (item_content_id != NULL)
		S_FREE(item_content_id);

	return NULL;
}
Example #5
0
static void read_utt_features(SUtterance *utt, SEbmlRead *ebmlReader, s_erc *error)
{
	uint32 id;
	char *feat_name = NULL;
	SObject *featObject = NULL;
	s_bool container_exhausted;


	S_CLR_ERR(error);

	/* read container */
	id = S_EBMLREAD_CALL(ebmlReader, container)(ebmlReader, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "read_utt_features",
				  "ebmlRead method \"container\" failed"))
		goto quit_error;

	/* sanity check id */
	S_EBML_ID_SANITY(id, S_UTT_EBML_FEATURES,
				"read_utt_features",
				"ID mismatch", error);

	while (1)
	{
		container_exhausted = S_EBMLREAD_CALL(ebmlReader, container_at_end)(ebmlReader, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "read_utt_features",
					  "ebmlRead method \"container_at_end\" failed"))
			goto quit_error;

		if (container_exhausted)
			break; /* we are finished reading the utterance features */

		/* peek id for utterance feature elements */
		id = S_EBMLREAD_CALL(ebmlReader, peek_id)(ebmlReader, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "read_utt_features",
					  "ebmlRead method \"peek_id\" failed"))
			goto quit_error;

		switch(id)
		{
		case S_UTT_EBML_FEAT_NAME:
		{
			/* feature elements are ordered (feat name, feat object),
			 * so we do it in one go
			 */
			read_feature(ebmlReader,
						 &feat_name, S_UTT_EBML_FEAT_NAME,
						 &featObject, S_UTT_EBML_FEAT_OBJECT,
						 error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "read_utt_features",
						  "Call to \"read_feature\" failed"))
				goto quit_error;

			/* set utterance feature */
			SUtteranceSetFeature(utt, feat_name, featObject, error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "read_utt_features",
						  "Call to \"SUtteranceSetFeature\" failed"))
				goto quit_error;

			/* feat name is copied */
			S_FREE(feat_name); /* sets to NULL */
			featObject = NULL;
			break;
		}
		default:
			/* unknown elements, skip */
			S_WARNING(S_FAILURE,
					  "read_utt_features",
					  "Skipping element with unknown id '0x%x'",
					  id);

			S_EBMLREAD_CALL(ebmlReader, element_skip)(ebmlReader, error);
			if (S_CHK_ERR(error, S_CONTERR,
						  "read_utt_features",
						  "ebmlRead method \"element_skip\" failed"))
				goto quit_error;
		}
	}

	/* here everything went OK */
	return;

	/* errors here, clean up code */
quit_error:
	if (feat_name != NULL)
		S_FREE(feat_name);

	if (featObject != NULL)
		S_DELETE(featObject, "read_utt_features", error);
}