Example #1
0
int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);

    QtQuick2ApplicationViewer viewer;

    //Logic logic(":/aggettivi.txt",  viewer.rootContext());
    Logic logic(":/indeterminativo",  viewer.rootContext());
    ExerciseVocabularyAnswer vocabulary(":/parole.txt");

    TwoSetExercise set;
    set.load("/tmp/sets.xml");

    set.print();
    viewer.rootContext()->setContextProperty("logic", &logic);
    viewer.rootContext()->setContextProperty("vocabulary", &vocabulary);

    viewer.rootContext()->setContextProperty("setexercise", &set);

    //viewer.addImportPath("qml/educazionik-framework/");
    viewer.setMainQmlFile(QStringLiteral("qml/educazionik-framework/main.qml"));
    viewer.showExpanded();

    return app.exec();
}
Example #2
0
	std::vector<Structure*> propagate(AbstractTheory* theory, Structure* structure) {
		// TODO: doens't work with cp support (because a.o.(?) backtranslation is not implemented)

		//Set MinisatID solver options
		auto data = SolverConnection::createsolver(0);

		auto clonetheory = theory->clone();
		auto result = structure->clone();
		auto voc = new Vocabulary("intern_voc");
		voc->add(clonetheory->vocabulary());
		result->changeVocabulary(voc);
		clonetheory->vocabulary(voc);

		auto grounding = GroundingInference<PCSolver>::doGrounding(clonetheory, result, NULL, NULL, NULL, true, data);

		auto mx = SolverConnection::initpropsolution(data);
		mx->execute();

		result->changeVocabulary(structure->vocabulary());

		auto translator = grounding->translator();
		auto entailed = mx->getEntailedLiterals();
		for (auto literal = entailed.cbegin(); literal < entailed.cend(); ++literal) {
			int atomnr = var(*literal);
			if (translator->isInputAtom(atomnr)) {
				auto symbol = translator->getSymbol(atomnr);
				auto args = translator->getArgs(atomnr);
				if (sign(*literal)) {
					result->inter(symbol)->makeFalseAtLeast(args);
				} else {
					result->inter(symbol)->makeTrueAtLeast(args);
				}
			}
		}
		result->clean();
		clonetheory->recursiveDelete();
		delete (voc);
		delete (data);
		delete (mx);

		if (not result->isConsistent()) {
			return std::vector<Structure*> { };
		}
		return {result};
	}
Example #3
0
BOOST_FIXTURE_TEST_CASE(test_bow, test::Peppers) {
    VocabularyPtr vocabulary(test::load<vis::Vocabulary>(VOCABULARY_FILE));
    BowHog extractor(*vocabulary);

    arma::fvec descriptors = extractor.extract(image);
    float sum = arma::sum(descriptors);

    printmat(descriptors);
    printvar(sum);

    BOOST_CHECK_EQUAL(extractor.numWords(), descriptors.size());
    BOOST_CHECK_CLOSE_FRACTION(sum, 1., 0.1);
}
Example #4
0
	static std::pair<AbstractGroundTheory*, StructureExtender*> createGroundingAndExtender(AbstractTheory* theory, Structure* structure,
			Vocabulary* outputvocabulary, Term* term, TraceMonitor* tracemonitor, bool nbModelsEquivalent, GroundingReceiver* solver) {
		if (theory == NULL || structure == NULL) {
			throw IdpException("Unexpected NULL-pointer.");
		}
		auto t = dynamic_cast<Theory*>(theory); // TODO handle other cases
		if (t == NULL) {
			throw notyetimplemented("Grounding of already ground theories");
		}
		if (t->vocabulary() != structure->vocabulary()) {
			throw IdpException("Grounding requires that the theory and structure range over the same vocabulary.");
		}
		auto m = new GroundingInference(t, structure, outputvocabulary, term, tracemonitor, nbModelsEquivalent, solver);
		auto grounding = m->ground();
		auto result = std::pair<AbstractGroundTheory*, StructureExtender*>{grounding, m->getManager()};
		delete(m);
		return result;
	}
Example #5
0
void SplitDefinitions::prepare() {
	savedOptions = BootstrappingUtils::setBootstrappingOptions();

	if (not getGlobal()->instance()->alreadyParsed("definitions")) {
		parsefile("definitions");
	}

	auto defnamespace = getGlobal()->getGlobalNamespace()->subspace("stdspace")->subspace("definitionbootstrapping");
	Assert(defnamespace != NULL);

	auto splitVoc = defnamespace->vocabulary("def_split_voc");
	Assert(splitVoc != NULL);
	sameDef = splitVoc->pred("samedef/2");
	Assert(sameDef != NULL);

	auto deptheo = defnamespace->theory("dependency");
	Assert(deptheo != NULL);
	splittheo = defnamespace->theory("def_split_theory");
	Assert(splittheo != NULL);
	splittheo = FormulaUtils::merge(splittheo, deptheo);
	Assert(splittheo != NULL);
}
Example #6
0
int main(int argc, char **argv){

    std::string filename(""), vocabulary("Vocabulary.voc");
    unsigned int scale = 5, dmst = 2, window = 3, detectorType = 0, descriptorType = 0, distanceType = 2;
    double baseSigma = 0.2, sigmaStep = 1.4, minPeak = 0.34, minPeakDistance = 0.001;
    bool useMaxRange = false;
    
    int i = 1;
    while(i < argc){
		if(strncmp("-filename", argv[i], sizeof("-filename")) == 0 ){
			filename = argv[++i];
			i++;
		} else if(strncmp("-vocabulary", argv[i], sizeof("-vocabulary")) == 0 ){
			vocabulary = argv[++i];
			i++;
		} else if(strncmp("-detector", argv[i], sizeof("-detector")) == 0 ){
			detectorType = atoi(argv[++i]);
			i++;
		} else if(strncmp("-descriptor", argv[i], sizeof("-descriptor")) == 0 ){
			descriptorType = atoi(argv[++i]);
			i++;
		} else if(strncmp("-distance", argv[i], sizeof("-distance")) == 0 ){
			distanceType = atoi(argv[++i]);
			i++;
		} else if(strncmp("-baseSigma", argv[i], sizeof("-baseSigma")) == 0 ){
			baseSigma = strtod(argv[++i], NULL);
			i++;
		} else if(strncmp("-sigmaStep", argv[i], sizeof("-sigmaStep")) == 0 ){
			sigmaStep = strtod(argv[++i], NULL);
			i++;
		} else if(strncmp("-minPeak", argv[i], sizeof("-minPeak")) == 0 ){
			minPeak = strtod(argv[++i], NULL);
			i++;
		} else if(strncmp("-minPeakDistance", argv[i], sizeof("-minPeakDistance")) == 0 ){
			minPeakDistance = strtod(argv[++i], NULL);
			i++;
		} else if(strncmp("-scale", argv[i], sizeof("-scale")) == 0 ){
			scale = atoi(argv[++i]);
			i++;
		} else if(strncmp("-dmst", argv[i], sizeof("-dmst")) == 0 ){
			dmst = atoi(argv[++i]);
			i++;
		} else if(strncmp("-window", argv[i], sizeof("-window")) == 0 ){
			window = atoi(argv[++i]);
			i++;
		} else if(strncmp("-help", argv[i], sizeof("-localSkip")) == 0 ){
			help();
			exit(0);
		} else {
			i++;
		}
    }
    
    if(!filename.size()){
		help();
		exit(-1);
    }
    

    
    
    CarmenLogWriter writer;
    CarmenLogReader reader;
    
    m_sensorReference = LogSensorStream(&reader, &writer);
    
    m_sensorReference.load(filename);
    
    SimpleMinMaxPeakFinder *m_peakMinMax = new SimpleMinMaxPeakFinder(minPeak, minPeakDistance);
    
    
    std::string detector("");
    switch(detectorType){
	case 0:
	    m_detectorCurvature = new CurvatureDetector(m_peakMinMax, scale, baseSigma, sigmaStep, dmst);
	    m_detectorCurvature->setUseMaxRange(useMaxRange);
	    m_detector = m_detectorCurvature;
	    detector = "curvature";
	    break;
	case 1:
	    m_detectorNormalEdge = new NormalEdgeDetector(m_peakMinMax, scale, baseSigma, sigmaStep, window);
	    m_detectorNormalEdge->setUseMaxRange(useMaxRange);
	    m_detector = m_detectorNormalEdge;
	    detector = "edge";
	    break;
	case 2:
	    m_detectorNormalBlob = new NormalBlobDetector(m_peakMinMax, scale, baseSigma, sigmaStep, window);
	    m_detectorNormalBlob->setUseMaxRange(useMaxRange);
	    m_detector = m_detectorNormalBlob;
	    detector = "blob";
	    break;
	case 3:
	    m_detectorRange = new RangeDetector(m_peakMinMax, scale, baseSigma, sigmaStep);
	    m_detectorRange->setUseMaxRange(useMaxRange);
	    m_detector = m_detectorRange;
	    detector = "range";
	    break;
	default:
	    std::cerr << "Wrong detector type" << std::endl;
	    exit(-1);
    }
    
    HistogramDistance<double> *dist = NULL;
    
    std::string distance("");
    switch(distanceType){
	case 0:
	    dist = new EuclideanDistance<double>();
	    distance = "euclid";
	    break;
	case 1:
	    dist = new Chi2Distance<double>();
	    distance = "chi2";
	    break;
	case 2:
	    dist = new SymmetricChi2Distance<double>();
	    distance = "symchi2";
	    break;
	case 3:
	    dist = new BatthacharyyaDistance<double>();
	    distance = "batt";
	    break;
	case 4:
	    dist = new KullbackLeiblerDistance<double>();
	    distance = "kld";
	    break;
	case 5:
	    dist = new JensenShannonDistance<double>();
	    distance = "jsd";
	    break;
	default:
	    std::cerr << "Wrong distance type" << std::endl;
	    exit(-1);
    }
    
    std::string descriptor("");
    switch(descriptorType){
	case 0:
	    m_betaGenerator = new BetaGridGenerator(0.02, 0.5, 4, 12);
	    m_betaGenerator->setDistanceFunction(dist);
	    m_descriptor = m_betaGenerator;
	    descriptor = "beta";
	    break;
	case 1:
	    m_shapeGenerator = new ShapeContextGenerator(0.02, 0.5, 4, 12);
	    m_shapeGenerator->setDistanceFunction(dist);
	    m_descriptor = m_shapeGenerator;
	    descriptor = "shape";
	    break;
	default:
	    std::cerr << "Wrong descriptor type" << std::endl;
	    exit(-1);
    }
    
    std::cerr << "Processing file:\t" << filename << "\nDetector:\t\t" << detector << "\nDescriptor:\t\t" << descriptor << "\nDistance:\t\t" << distance << "\nVocabulary:\t\t" << vocabulary << std::endl;
    
    std::ifstream vocabularyStream(vocabulary.c_str());
    boost::archive::binary_iarchive vocabularyArchive(vocabularyStream);
    vocabularyArchive >> histogramVocabulary;
    
    m_sensorReference.seek(0,END);
    unsigned int end = m_sensorReference.tell();
    m_sensorReference.seek(0,BEGIN);

    m_pointsReference.resize(end + 1);
    m_posesReference.resize(end + 1);
    
    writePoses();
    try {
      std::string featureFile = filename.substr(0,filename.find_last_of('.')) + ".flt";
      std::ifstream featureStream(featureFile.c_str());
      boost::archive::binary_iarchive featureArchive(featureStream);
      std::cout << "Loading feature file " << featureFile << " ...";
      featureArchive >> m_pointsReference;
      std::cout << " done." << std::endl;
    } catch(boost::archive::archive_exception& exc) {
      detectLog();
      countLog();
      describeLog();
    }
    
    std::string bowFile = filename.substr(0,filename.find_last_of('.')) + ".bow";
    std::ofstream bowStream(bowFile.c_str());
    
    writeBoW(bowStream);
    
}
Example #7
0
Vocabulary* InternalArgument::get<Vocabulary*>() {
	return vocabulary();
}