NormalizerPerformanceTest::NormalizerPerformanceTest(int32_t argc, const char* argv[], UErrorCode& status)
: UPerfTest(argc,argv,status), options(0) {
    NFDBuffer = NULL;
    NFCBuffer = NULL;
    NFDBufferLen = 0;
    NFCBufferLen = 0;
    NFDFileLines = NULL;
    NFCFileLines = NULL;

    if(status== U_ILLEGAL_ARGUMENT_ERROR){
       fprintf(stderr,gUsageString, "normperf");
       return;
    }

    if(U_FAILURE(status)){
        fprintf(stderr, "FAILED to create UPerfTest object. Error: %s\n", u_errorName(status));
        return;
    }

    _remainingArgc = u_parseArgs(_remainingArgc, (char **)argv, (int32_t)(LENGTHOF(cmdLineOptions)), cmdLineOptions);
    if(cmdLineOptions[0].doesOccur && cmdLineOptions[0].value!=NULL) {
        options=(int32_t)strtol(cmdLineOptions[0].value, NULL, 16);
    }

    if(line_mode){
        ULine* filelines = getLines(status);
        if(U_FAILURE(status)){
            fprintf(stderr, "FAILED to read lines from file and create UPerfTest object. Error: %s\n", u_errorName(status));
            return;
        }
        NFDFileLines = new ULine[numLines];
        NFCFileLines = new ULine[numLines];
    
        for(int32_t i=0;i<numLines;i++){
            normalizeInput(&NFDFileLines[i],filelines[i].name,filelines[i].len,UNORM_NFD, options);
            normalizeInput(&NFCFileLines[i],filelines[i].name,filelines[i].len,UNORM_NFC, options);

        }
    }else if(bulk_mode){
        int32_t srcLen = 0;
        const UChar* src = getBuffer(srcLen,status);
        NFDBufferLen = 0;
        NFCBufferLen = 0;

        if(U_FAILURE(status)){
            fprintf(stderr, "FAILED to read buffer from file and create UPerfTest object. Error: %s\n", u_errorName(status));
            return;
        }
         
        NFDBuffer = normalizeInput(NFDBufferLen,src,srcLen,UNORM_NFD, options);
        NFCBuffer = normalizeInput(NFCBufferLen,src,srcLen,UNORM_NFC, options);
    }
    
}
Beispiel #2
0
_Bool checkGameOver(_Bool* alreadyChosen, char* answer, int lives){
  if (lives <= 0){
      printf("\nanswer was: %s\n", answer);
      printf("epic fail!\n");
    return true;
  }
  for (int i = 0; i < answer[i] != '\0'; i++){
    if(normalizeInput(answer[i]) != -1){ // check only letters
      if(alreadyChosen[tolower(answer[i]) - 'a'] == false){
	return false;
      }
    }
  }
  printf("\nanswer: %s\n", answer);
  printf("epic win!\n");
  return true;
}
Beispiel #3
0
  void
  XorgFunction::applyi(int dxMickey, int dyMickey, int *dxPixel, int *dyPixel,
		      TimeStamp::inttime timestamp) {

    if (normalize)
      normalizeInput(&dxMickey, &dyMickey, input);
    // std::cerr << "XorgFunction::apply:" << timestamp << std::endl ;
    if (timestamp==TimeStamp::undef) 
      timestamp = TimeStamp::createAsInt() ;
    if (epoch==TimeStamp::undef)
      epoch = timestamp ;
    int first = 0, num = 2 ;
    int valuators[2] = {dxMickey, dyMickey} ;
    int ms = (timestamp-epoch)/TimeStamp::one_millisecond ;
    // std::cerr << "XorgFunction::apply: " << timestamp << "/" << ms << " " << dxMickey << " " << dyMickey << std::endl ;
    if (dev->valuator->accelScheme.AccelSchemeProc)
      dev->valuator->accelScheme.AccelSchemeProc(dev, first, num, valuators, ms) ;
    if (normalize)
      normalizeOutput(valuators, valuators + 1, output);
    *dxPixel = valuators[0] ;
    *dyPixel = valuators[1] ;
  }
Beispiel #4
0
std::unique_ptr<Builder> ConfigParser::getBuilder(
        Json::Value json,
        std::shared_ptr<arbiter::Arbiter> arbiter)
{
    if (!arbiter) arbiter = std::make_shared<arbiter::Arbiter>();

    const bool verbose(json["verbose"].asBool());

    const Json::Value d(defaults());
    for (const auto& k : d.getMemberNames())
    {
        if (!json.isMember(k)) json[k] = d[k];
    }

    const std::string outPath(json["output"].asString());
    const std::string tmpPath(json["tmp"].asString());
    const std::size_t threads(json["threads"].asUInt64());

    normalizeInput(json, *arbiter);
    auto fileInfo(extract<FileInfo>(json["input"]));

    if (!json["force"].asBool())
    {
        auto builder = tryGetExisting(
                json,
                *arbiter,
                outPath,
                tmpPath,
                threads);

        if (builder)
        {
            if (verbose) builder->verbose(true);

            // If we have more paths to add, add them to the manifest.
            // Otherwise we might be continuing a partial build, in which case
            // the paths to be built are already outstanding in the manifest.
            //
            // It's plausible that the input field could be empty to continue
            // a previous build.
            if (json["input"].isArray()) builder->append(fileInfo);
            return builder;
        }
    }

    const bool compress(json["compress"].asUInt64());
    const bool trustHeaders(json["trustHeaders"].asBool());
    auto cesiumSettings(getCesiumSettings(json["formats"]));
    bool absolute(json["absolute"].asBool());

    if (cesiumSettings)
    {
        absolute = true;
        json["reprojection"]["out"] = "EPSG:4978";
    }

    auto reprojection(maybeCreate<Reprojection>(json["reprojection"]));

    std::unique_ptr<std::vector<double>> transformation;
    std::unique_ptr<Delta> delta;
    if (!absolute && Delta::existsIn(json)) delta = makeUnique<Delta>(json);

    // If we're building from an inference, then we already have these.  A user
    // could have also pre-supplied them in the config.
    //
    // Either way, these three values are prerequisites for building, so if
    // we're missing any we'll need to infer them from the files.
    std::size_t numPointsHint(json["numPointsHint"].asUInt64());
    auto boundsConforming(maybeCreate<Bounds>(json["bounds"]));
    auto schema(maybeCreate<Schema>(json["schema"]));

    const bool needsInference(!boundsConforming || !schema || !numPointsHint);

    if (needsInference)
    {
        if (verbose)
        {
            std::cout << "Performing dataset inference..." << std::endl;
        }

        Inference inference(
                fileInfo,
                reprojection.get(),
                trustHeaders,
                !absolute,
                tmpPath,
                threads,
                verbose,
                !!cesiumSettings,
                arbiter.get());

        inference.go();

        // Overwrite our initial fileInfo with the inferred version, which
        // contains details for each file instead of just paths.
        fileInfo = inference.fileInfo();

        if (!absolute && inference.delta())
        {
            if (!delta) delta = makeUnique<Delta>();

            if (!json.isMember("scale"))
            {
                delta->scale() = inference.delta()->scale();
            }

            if (!json.isMember("offset"))
            {
                delta->offset() = inference.delta()->offset();
            }
        }

        if (!boundsConforming)
        {
            boundsConforming = makeUnique<Bounds>(inference.bounds());

            if (verbose)
            {
                std::cout << "Inferred: " << inference.bounds() << std::endl;
            }
        }

        if (!schema)
        {
            auto dims(inference.schema().dims());
            if (delta)
            {
                const Bounds cube(
                        Metadata::makeScaledCube(
                            *boundsConforming,
                            delta.get()));
                dims = Schema::deltify(cube, *delta, inference.schema()).dims();
            }

            const std::size_t pointIdSize([&fileInfo]()
            {
                std::size_t max(0);
                for (const auto& f : fileInfo)
                {
                    max = std::max(max, f.numPoints());
                }

                if (max <= std::numeric_limits<uint32_t>::max()) return 4;
                else return 8;
            }());

            const std::size_t originSize([&fileInfo]()
            {
                if (fileInfo.size() <= std::numeric_limits<uint32_t>::max())
                    return 4;
                else
                    return 8;
            }());

            dims.emplace_back("OriginId", "unsigned", originSize);
            dims.emplace_back("PointId", "unsigned", pointIdSize);

            schema = makeUnique<Schema>(dims);
        }

        if (!numPointsHint) numPointsHint = inference.numPoints();

        if (const std::vector<double>* t = inference.transformation())
        {
            transformation = makeUnique<std::vector<double>>(*t);
        }
    }

    auto subset(maybeAccommodateSubset(json, *boundsConforming, delta.get()));

    json["numPointsHint"] = static_cast<Json::UInt64>(numPointsHint);
    Structure structure(json);
    Structure hierarchyStructure(Hierarchy::structure(structure, subset.get()));
    const HierarchyCompression hierarchyCompression(
            compress ? HierarchyCompression::Lzma : HierarchyCompression::None);

    const auto ep(arbiter->getEndpoint(json["output"].asString()));
    const Manifest manifest(fileInfo, ep);

    const Metadata metadata(
            *boundsConforming,
            *schema,
            structure,
            hierarchyStructure,
            manifest,
            trustHeaders,
            compress,
            hierarchyCompression,
            reprojection.get(),
            subset.get(),
            delta.get(),
            transformation.get(),
            cesiumSettings.get());

    OuterScope outerScope;
    outerScope.setArbiter(arbiter);

    auto builder =
        makeUnique<Builder>(metadata, outPath, tmpPath, threads, outerScope);

    if (verbose) builder->verbose(true);
    return builder;
}
Beispiel #5
0
int main(){
	int lives = 7;
	FILE* fp = fopen("Ulm.hm","r");
	char buffer[MAXBUFFLENGTH * BUFFERELEMENTS]; 
	reservoirSampling(buffer, fp);
	_Bool name = false;
	char answer[42];
	int k = 0;
	
	/*printing the question and saving the answer into an array*/
	for (int i = 0; i < BUFFERELEMENTS; ++i){
		for (int j = 0; buffer[i*MAXBUFFLENGTH + j] != '\n'; ++j){
			if(name == false){
				printf("%c",buffer[i*MAXBUFFLENGTH + j]);
			} else {
			  if (buffer[i*MAXBUFFLENGTH + j] != 0){
			    answer[k++] = buffer[i*MAXBUFFLENGTH + j];
			  }
			}
			if (buffer[i*MAXBUFFLENGTH + j] == '\t')
				name = true;
		}
		printf("\n");
	}
	//printf("answer: %s\n", answer);
	
	/* array of letters that have already been chosen */
	_Bool alreadyChosen[32] = { 0 };
	int input;
	
	
	loop: // goto label
	if (checkGameOver(alreadyChosen, answer, lives))
	  goto gameOver;
	printf("%d\t",lives);
	for (int i = 0; i < 32; ++i){
	  if(alreadyChosen[i] == true){
	    printf("%c", (char)('a' + i)); // print all the letters that have already been chosen 
	  }
	}
	printf("\t\t");
	
	/* printing the word to be guessed */
	for (int i = 0; i < answer[i] != '\0'; i++){
	  if(answer[i] == ' ' || answer[i] == '-' ||answer[i] == '.' || alreadyChosen[tolower(answer[i]) - 'a'] == true){
	    printf("%c", answer[i]);
	  } else {
	      printf("%c", '_');
	  }
	}
	printf("\n");

	while((input = getchar()) != '\n'){
	  if(normalizeInput(input) == -1){ 
	    --lives; // ivalid input
	  }
	  if(alreadyChosen[normalizeInput(input) - 'a'] == true){
	    --lives; // letter already chosen
	  } 
	  for (int i = 0; i < answer[i] != '\0'; i++){
	    if (input == tolower(answer[i])){
	      alreadyChosen[normalizeInput(input) - 'a'] = true; // right choice
	      goto loop;
	    }
	  }
	  alreadyChosen[normalizeInput(input) - 'a'] = true; // wrong choice
	  --lives;
	}
	goto loop;
	
	gameOver:
	fclose(fp);
	return 0;
}