TskModule::Status TskReportPluginModule::report()
{
    const std::string MSG_PREFIX = "TskReportPluginModule::report : ";
    TskModule::Status status = TskModule::OK;
    try
    {
        if (!isLoaded())
        {
            std::stringstream msg;
            msg << MSG_PREFIX << "'" << getPath() << "' is not loaded";
            throw TskException(msg.str());
        }

        if (!hasSymbol(TskPluginModule::REPORT_SYMBOL)) 
        {
            std::stringstream msg;
            msg << MSG_PREFIX << "'" << getPath() << "' does not define the '" << TskPluginModule::REPORT_SYMBOL << "' symbol";
            throw TskException(msg.str());
        }

        typedef TskModule::Status (*ReportFunc)();
        ReportFunc report = (ReportFunc)getSymbol(TskPluginModule::REPORT_SYMBOL);
        status = report();
    }
    catch (TskException &ex) 
    {
        std::stringstream msg;
        msg << MSG_PREFIX << "TskException executing report function of " << getName() << ": " << ex.message();
        LOGERROR(msg.str());
        status = TskModule::FAIL;
    }
    catch (Poco::Exception &ex) 
    {
        std::stringstream msg;
        msg << MSG_PREFIX <<  "Poco::Exception executing report function of "  << getName() << ": " << ex.displayText();
        LOGERROR(msg.str());
        status = TskModule::FAIL;
    }
    catch (std::exception &ex) 
    {
        std::stringstream msg;
        msg << MSG_PREFIX <<  "std::exception executing report function of "  << getName() << ": " << ex.what();
        LOGERROR(msg.str());
        status = TskModule::FAIL;
    }
    catch (...)
    {
        std::stringstream msg;
        msg << MSG_PREFIX << "unrecognized exception executing report function of "  << getName();
        LOGERROR(msg.str());
        status = TskModule::FAIL;
    }

    return status;
}
Exemple #2
0
	const Tuple2AtomMap& getIntroducedLiteralsFor(PFSymbol* symbol) const{
		if(not hasSymbol(symbol)){
			return emptymap;
		}
		auto offset = getSymbol(symbol);
		Assert(offset.offset!=-1);
		if(offset.functionlist){
			throw notyetimplemented("Lazy grounding with support for function symbols in the grounding");
		}else{
			return symbols[offset.offset]->tuple2atom;
		}
	}
// Throw exception if the module does not have REPORT_SYMBOL
void TskReportPluginModule::checkInterface()
{
    if (!isLoaded())
        throw TskException("Module is not loaded");

    if (!hasSymbol(TskPluginModule::REPORT_SYMBOL)) {
        std::wstringstream msg;
        msg << L"TskReportPluginModule::checkInterface - Module does not contain the \""
            << TskPluginModule::REPORT_SYMBOL.c_str() << L"\" symbol : " << getPath().c_str();
        LOGERROR(msg.str());

        throw TskException("Module missing required symbol.");
    }
}
Exemple #4
0
// Returns the updated expression e, deleting as necessary
// argi is copied when used
// TODO this can be done with an if and a for each..
// The caller deallocates args and the return value (either returns e unchanged or deletes it while creating something new)
SPExpression deepReplaceArg(SPExpression e, const vector<SPExpression>& args) {
    if (hasSymbol(e, argSymbol)) {
        Tassert(e->subexpressions.size() == 1, "arg should be used with one subexpression");
        long j = strtol(e->subexpressions[0]->symbol); // TODO detect invalid
        Tassert(j < args.size() && j >= 0, "invalid number %d in arg, parsed from %s, args.size() = %d", j, e->subexpressions[0]->symbol.c_str(), args.size());
        return deepCopy(args[j]);
    }

    // Replace subexpressions with results from deepReplaceArg
    for (auto& se : e->subexpressions) {
        assert(e != se);
        se = deepReplaceArg(std::move(se), args);
    }
    return e;
}
void TskReportPluginModule::checkInterface()
{
    const std::string MSG_PREFIX = "TskReportPluginModule::checkInterface : ";

    if (!isLoaded())
    {
        std::stringstream msg;
        msg << MSG_PREFIX << getPath() << " is not loaded";
        LOGERROR(msg.str());
        throw TskException(msg.str());
    }

    if (!hasSymbol(TskPluginModule::REPORT_SYMBOL)) 
    {
        std::stringstream msg;
        msg << MSG_PREFIX << getPath() << " does not define the required '" << TskPluginModule::REPORT_SYMBOL << "' symbol";
        throw TskException(msg.str());
    }
}
Exemple #6
0
static crfsuite_instance_t* create_phrase_instance ( SItem* phrase,
                                                 crfsuite_dictionary_t* attrs,
                                                 crfsuite_dictionary_t* labels,
                                                 s_erc *error)
{
	crfsuite_instance_t * result = malloc ( sizeof(crfsuite_instance_t) );
	int i = 0;
	int L = labels->num(labels);
	const SItem* itrItem = NULL;
	const SItem* itrItemNext = NULL;
	const SItem* finishItem = NULL;

	const char* lbl[] = {"num", "sym", "cap", "p1", "p2", "p3",
							"s1", "s2", "s3", "P1", "P2", "P3", "P4",
							"S1", "S2", "S3", "S4", "S5", "S6", "w" };

	const int words_length = 19;
	const char* words[19] = {			 NULL, NULL, NULL, NULL, NULL,
										NULL, NULL, NULL, NULL, NULL,
										NULL, NULL, NULL, NULL, NULL,
										NULL, NULL, NULL, NULL};
	int position = 0;

	int lbl_counter = 0;
	char buffer[8192];

	crfsuite_instance_init ( result );

	itrItemNext = SItemPathToItem (phrase, "daughter.R:Token.parent", error);
	if (S_CHK_ERR(error, S_CONTERR,
			  "create_phrase_instance",
			  "Call to \"SItemPathToItem\" failed"))
		return NULL;

	finishItem = SItemPathToItem (phrase, "n.daughter.R:Token.parent", error);
	if (S_CHK_ERR(error, S_CONTERR,
			  "create_phrase_instance",
			  "Call to \"SItemPathToItem\" failed"))
		return NULL;

	int counter = 0;

	while ( itrItemNext != finishItem && itrItemNext != NULL && counter < 9)
	{
		words[counter] = SItemGetName(itrItemNext, error);
		if (S_CHK_ERR(error, S_CONTERR,
				  "create_phrase_instance",
				  "Call to \"SItemGetName\" failed"))
			return NULL;

		counter++;

		itrItemNext = SItemNext(itrItemNext, error);
		if (S_CHK_ERR(error, S_CONTERR,
				  "create_phrase_instance",
				  "Call to \"SItemNext\" failed"))
			return NULL;
	}

	itrItem = SItemPathToItem (phrase, "daughter.R:Token.parent", error);
	if (S_CHK_ERR(error, S_CONTERR,
			  "create_phrase_instance",
			  "Call to \"SItemPathToItem\" failed"))
		return NULL;

	while ( itrItem != finishItem && itrItem != NULL)
	{
		/* Extraction of the features for each token */
		const char *tokenName = SItemGetName (itrItem, error);
		if (S_CHK_ERR(error, S_CONTERR,
				  "create_phrase_instance",
				  "Call to \"SItemGetName\" failed"))
			return NULL;

        lbl_counter = 0;

		/* Extraction of label's ID */
		int tokenID = labels->to_id(labels, "UNK");
		int attribute_id;

		/* If unknown the set the 0 labels (unknown) */
		if (tokenID < 0)
			tokenID = L;

		crfsuite_item_t itemToken;
		crfsuite_attribute_t attribute;

		crfsuite_item_init(&itemToken);

		const char *feat = NULL;
		s_bool found = FALSE;


		/* if token contains numbers */
		found = hasNumber (tokenName, error);
		if (S_CHK_ERR(error, S_CONTERR,
				  "create_phrase_instance",
				  "Call to \"hasNumber\" failed"))
			return NULL;

		sprintf(buffer, "%s[%d]=%s", lbl[lbl_counter], 0, found? "Y" : "N");
		lbl_counter++;


		attribute_id = attrs->to_id (attrs,buffer);
		crfsuite_attribute_set (&attribute, attribute_id, 1.0);
		crfsuite_item_append_attribute(&itemToken, &attribute);


		/* if token contains symbols */
		found = hasSymbol (tokenName, error);
		if (S_CHK_ERR(error, S_CONTERR,
				  "create_phrase_instance",
				  "Call to \"hasSymbol\" failed"))
			return NULL;

		sprintf(buffer, "%s[%d]=%s", lbl[lbl_counter], 0, found? "Y" : "N");
		lbl_counter++;

		attribute_id = attrs->to_id (attrs,buffer);
		crfsuite_attribute_set (&attribute, attribute_id, 1.0);
		crfsuite_item_append_attribute(&itemToken, &attribute);


		/* if token contains Capitals */
		found = hasCapital (tokenName, error);
		if (S_CHK_ERR(error, S_CONTERR,
				  "create_phrase_instance",
				  "Call to \"hasCapital\" failed"))
			return NULL;

		sprintf(buffer, "%s[%d]=%s", lbl[lbl_counter], 0, found? "Y" : "N");
		lbl_counter++;

		attribute_id = attrs->to_id (attrs,buffer);
		crfsuite_attribute_set (&attribute, attribute_id, 1.0);
		crfsuite_item_append_attribute(&itemToken, &attribute);


		/* Prefixes of 1 to 3 chars of token */
		i = 1;
		while ( i < 4 )
		{
			feat = getFirstChars ( tokenName, i, error );
			if (S_CHK_ERR(error, S_CONTERR,
					  "create_phrase_instance",
					  "Call to \"getFirstChars\" failed"))
				return NULL;

			if ( feat == NULL )
				feat = "__nil__";

			sprintf(buffer, "%s[%d]=%s", lbl[lbl_counter], 0, feat);
			lbl_counter++;

			attribute_id = attrs->to_id (attrs,buffer);
			crfsuite_attribute_set (&attribute, attribute_id, 1.0);
			crfsuite_item_append_attribute(&itemToken, &attribute);

			i += 1;
		}

		/* Suffixes of 1 to 3 chars of token */
		i = 1;
		while ( i < 4 )
		{
			feat = getLastChars ( tokenName, i, error );
			if (S_CHK_ERR(error, S_CONTERR,
					  "create_phrase_instance",
					  "Call to \"getLastChars\" failed"))
				return NULL;

			if ( feat == NULL )
				feat = "__nil__";

			sprintf(buffer, "%s[%d]=%s", lbl[lbl_counter], 0, feat);
			lbl_counter++;

			attribute_id = attrs->to_id (attrs,buffer);
			crfsuite_attribute_set (&attribute, attribute_id, 1.0);
			crfsuite_item_append_attribute(&itemToken, &attribute);

			i += 1;
		}

		/* Prefixes of 1 to 4 chars of token without duplicates adjacent */
		i = 1;
		while ( i < 5 )
		{
			feat = getFirstChars ( removeDoubles(tokenName, error), i, error );
			if (S_CHK_ERR(error, S_CONTERR,
					  "create_phrase_instance",
					  "Call to \"removeDoubles\" failed"))
				return NULL;
			if (S_CHK_ERR(error, S_CONTERR,
					  "create_phrase_instance",
					  "Call to \"getFirstChars\" failed"))
				return NULL;

			if ( feat == NULL )
				feat = "__nil__";

			sprintf(buffer, "%s[%d]=%s", lbl[lbl_counter], 0, feat);
			lbl_counter++;

			attribute_id = attrs->to_id (attrs,buffer);
			crfsuite_attribute_set (&attribute, attribute_id, 1.0);
			crfsuite_item_append_attribute(&itemToken, &attribute);

			i += 1;
		}

		/* Suffixes of 1 to 6 chars of token without duplicates adjacent */
		i = 1;
		while ( i < 7 )
		{
			feat = getLastChars ( removeDoubles(tokenName, error), i, error );
			if (S_CHK_ERR(error, S_CONTERR,
					  "create_phrase_instance",
					  "Call to \"removeDoubles\" failed"))
				return NULL;
			if (S_CHK_ERR(error, S_CONTERR,
					  "create_phrase_instance",
					  "Call to \"getFirstChars\" failed"))
				return NULL;

			if ( feat == NULL )
				feat = "__nil__";

			sprintf(buffer, "%s[%d]=%s", lbl[lbl_counter], 0, feat);
			lbl_counter++;

			attribute_id = attrs->to_id (attrs,buffer);
			crfsuite_attribute_set (&attribute, attribute_id, 1.0);
			crfsuite_item_append_attribute(&itemToken, &attribute);

			i += 1;
		}

		/* Words features */

		sprintf(buffer, "%s[%d]=%s", lbl[lbl_counter], 0, words[(position+0+words_length)%words_length]);

		attribute_id = attrs->to_id (attrs,buffer);
		crfsuite_attribute_set (&attribute, attribute_id, 1.0);
		crfsuite_item_append_attribute(&itemToken, &attribute);

		const char *tmp = words[(position-1+words_length)%words_length];
		if(tmp!=NULL)
		{
			sprintf(buffer, "%s[%d]=%s", lbl[lbl_counter], -1, tmp);

			attribute_id = attrs->to_id (attrs,buffer);
			crfsuite_attribute_set (&attribute, attribute_id, 1.0);
			crfsuite_item_append_attribute(&itemToken, &attribute);
		}

		tmp = words[(position+1+words_length)%words_length];
		if(tmp!=NULL)
		{
			sprintf(buffer, "%s[%d]=%s", lbl[lbl_counter], 1, tmp);

			attribute_id = attrs->to_id (attrs,buffer);
			crfsuite_attribute_set (&attribute, attribute_id, 1.0);
			crfsuite_item_append_attribute(&itemToken, &attribute);
		}

		tmp = words[(position-2+words_length)%words_length];
		if(tmp!=NULL)
		{
			sprintf(buffer, "%s[%d]=%s", lbl[lbl_counter], -2, tmp);

			attribute_id = attrs->to_id (attrs,buffer);
			crfsuite_attribute_set (&attribute, attribute_id, 1.0);
			crfsuite_item_append_attribute(&itemToken, &attribute);
		}

		tmp = words[(position+2+words_length)%words_length];
		if(tmp!=NULL)
		{
			sprintf(buffer, "%s[%d]=%s", lbl[lbl_counter], 2, tmp);

			attribute_id = attrs->to_id (attrs,buffer);
			crfsuite_attribute_set (&attribute, attribute_id, 1.0);
			crfsuite_item_append_attribute(&itemToken, &attribute);
		}

		const char * tmp1 = NULL;
		i = 0;
		while ( i < 4 )
		{
			tmp = words[(position-2+i+words_length)%words_length];
			tmp1 = words[(position-1+i+words_length)%words_length];
			if( tmp!=NULL && tmp1 != NULL )
			{
				sprintf(buffer, "%s[%d]|%s[%d]=%s|%s", lbl[lbl_counter], -2+i,
													   lbl[lbl_counter], -1+i,
													   tmp, tmp1 );

				attribute_id = attrs->to_id (attrs,buffer);
				crfsuite_attribute_set (&attribute, attribute_id, 1.0);
				crfsuite_item_append_attribute(&itemToken, &attribute);
			}
			i++;
		}

		const char * tmp2 = NULL;
		i = 0;
		while ( i < 3 )
		{
			tmp = words[(position-2+i+words_length)%words_length];
			tmp1 = words[(position-1+i+words_length)%words_length];
			tmp2 = words[(position+0+i+words_length)%words_length];
			if( tmp!=NULL && tmp1 != NULL && tmp2 != NULL )
			{
				sprintf(buffer, "%s[%d]|%s[%d]|%s[%d]=%s|%s|%s",
													   lbl[lbl_counter], -2+i,
													   lbl[lbl_counter], -1+i,
													   lbl[lbl_counter], +0+i,
													   tmp, tmp1, tmp2 );

				attribute_id = attrs->to_id (attrs,buffer);
				crfsuite_attribute_set (&attribute, attribute_id, 1.0);
				crfsuite_item_append_attribute(&itemToken, &attribute);
			}
			i++;
		}

		const char * tmp3 = NULL;
		i = 0;
		while ( i < 2 )
		{
			tmp  = words[(position-2+i+words_length)%words_length];
			tmp1 = words[(position-1+i+words_length)%words_length];
			tmp2 = words[(position+0+i+words_length)%words_length];
			tmp3 = words[(position+1+i+words_length)%words_length];
			if( tmp!=NULL && tmp1 != NULL && tmp2 != NULL && tmp3 != NULL )
			{
				sprintf(buffer, "%s[%d]|%s[%d]|%s[%d]|%s[%d]=%s|%s|%s|%s",
													   lbl[lbl_counter], -2+i,
													   lbl[lbl_counter], -1+i,
													   lbl[lbl_counter], +0+i,
													   lbl[lbl_counter], +1+i,
													   tmp, tmp1, tmp2, tmp3 );

				attribute_id = attrs->to_id (attrs,buffer);
				crfsuite_attribute_set (&attribute, attribute_id, 1.0);
				crfsuite_item_append_attribute(&itemToken, &attribute);
			}
			i++;
		}

		tmp  = words[(position-2+words_length)%words_length];
		tmp1 = words[(position-1+words_length)%words_length];
		tmp2 = words[(position+0+words_length)%words_length];
		tmp3 = words[(position+1+words_length)%words_length];
		const char * tmp4 = words[(position+2+words_length)%words_length];
		if( tmp!=NULL && tmp1 != NULL && tmp2 != NULL && tmp3 != NULL && tmp4 != NULL )
		{
			sprintf(buffer, "%s[%d]|%s[%d]|%s[%d]|%s[%d]|%s[%d]=%s|%s|%s|%s|%s",
												   lbl[lbl_counter], -2,
												   lbl[lbl_counter], -1,
												   lbl[lbl_counter], +0,
												   lbl[lbl_counter], +1,
												   lbl[lbl_counter], +2,
												   tmp, tmp1, tmp2, tmp3, tmp4 );

			attribute_id = attrs->to_id (attrs,buffer);
			crfsuite_attribute_set (&attribute, attribute_id, 1.0);
			crfsuite_item_append_attribute(&itemToken, &attribute);
		}

		tmp  = words[(position+0+words_length)%words_length];

		i = 1;
		while ( i < 10 )
		{
			tmp1  = words[(position-i+words_length)%words_length];
			if ( tmp1 != NULL )
			{
				sprintf(buffer, "%s[%d]|%s[%d]=%s|%s", lbl[lbl_counter], 0,
													   lbl[lbl_counter], 0-i,
													   tmp, tmp1 );

				attribute_id = attrs->to_id (attrs,buffer);
				crfsuite_attribute_set (&attribute, attribute_id, 1.0);
				crfsuite_item_append_attribute(&itemToken, &attribute);
			}
			i++;
		}

		i = 1;
		while ( i < 10 )
		{
			tmp1  = words[(position+i+words_length)%words_length];
			if ( tmp1 != NULL )
			{
				sprintf(buffer, "%s[%d]|%s[%d]=%s|%s", lbl[lbl_counter], 0,
													   lbl[lbl_counter], 0+i,
													   tmp, tmp1 );

				attribute_id = attrs->to_id (attrs,buffer);
				crfsuite_attribute_set (&attribute, attribute_id, 1.0);
				crfsuite_item_append_attribute(&itemToken, &attribute);
			}
			i++;
		}




		/* Update words array */
		position++;
		if ( itrItemNext != NULL )
		{
			words[position+9] = SItemGetName (itrItemNext, error);
			if (S_CHK_ERR(error, S_CONTERR,
					  "create_phrase_instance",
					  "Call to \"SItemNext\" failed"))
				return NULL;

			itrItemNext = SItemNext ( itrItemNext, error );
			if (S_CHK_ERR(error, S_CONTERR,
					  "create_phrase_instance",
					  "Call to \"SItemNext\" failed"))
				return NULL;
		}
		else
			words[position+9] = NULL;

		itrItem = SItemNext ( itrItem, error );
		if (S_CHK_ERR(error, S_CONTERR,
				  "create_phrase_instance",
				  "Call to \"SItemNext\" failed"))
			return NULL;

		crfsuite_instance_append(result, &itemToken, tokenID);
		crfsuite_item_finish(&itemToken);
	}

	return result;

}
Exemple #7
0
void validateRule(const SPExpression& rule) {
    assert(hasSymbol(rule, ruleSymbol));
    assert(rule->subexpressions[0]->symbol.length() > 0, "symbol of rule must have nonzero length");
    assert(rule->subexpressions[0]->subexpressions.size() == 0, "symbol of rule may not have children");
}