Giter Site home page Giter Site logo

hunspellphp's People

Contributors

bartheyrman22 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

hunspellphp's Issues

hunspell command line command not working for me

return shell_exec(sprintf("LANG=%s; echo '%s' | hunspell -d %s", $this->encoding, $input, $this->language));

The referenced line does not appear to work on my windows machine or my centOS7 server. The output from the command is empty. I've had to hack my version of this function to do this, and please don't mind the 'hackyness' as I'm not super fluent with the whole command line interactivity stuff.

Oh by the way I also added support for a dictionary file. The reasoning is that the site I'm using this for has lots of brand name stuff that comes up as misspellings so I wrote a script to weight every word on the site and created a hunspell dictionary file out of the big / common ones. It works well, though I didnt put a lot of thought into keeping the code neat and clean as I didn't really expect anyone to see this lol.

As to a run down of what I'm doing, is I'm loading the dictionary file into memory if it exists, Then I save it as a temp file with the $input var appended (not sure why anymore I did this a while back - however since I'm not providing the $Input var to the command line that must be related to the reason or is otherwise how hunspell is getting the $input). After that I create an empty temp file to dump the output of the shell command. After the command runs I get the output from the temp file, delete both files and return the output.

Do you approve of this? Do you want me to do a PR and clean it up or if you want to implement it your self that would be cool. I'd also be interested on your take as to why there is no output from the provided command. I think it has something to do with the path vars and my environment or something.

Obviously the dictionary file support would have to be added to the actual options rather than hard coded.

` $dictionary_file = $_SERVER["DOCUMENT_ROOT"] . ".dictionary.txt";

	if(file_exists($dictionary_file)) {
		$custom_dictionary = file_get_contents($dictionary_file);
	} else {
		$custom_dictionary = "";
	}

	$tmp = tempnam(sys_get_temp_dir(), 'hunspell');
	file_put_contents($tmp, $custom_dictionary . "\n" . $input);

	$tmp2 = tempnam(sys_get_temp_dir(), 'hunspell');
	if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
		$cmd = 'C:\\hunspell\\bin\\hunspell.exe -a -d en_US ' . $tmp . " > " . $tmp2;
	} else {
		$cmd = 'hunspell -a -d en_US ' . $tmp . " > " . $tmp2;
	}

	shell_exec($cmd);

	unlink($tmp);

	$out = file_get_contents($tmp2);
	unlink($tmp2);

	$out = explode("\n", trim($out));
	array_shift($out);
	$out = implode(" ", $out);

	return $out;`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.