Examples/Tutorials of Hunspell - spell-checking

I've tried looking through the documentation found on SourceForge with Hunspell, but I'm still lost. Are there any decent examples of hunspell that a C++ beginner would be able to follow? Failing that, are there any free/opensource spellcheckers that are easier to use?

I agree that their website is a little bit difficult to navigate and there aren't many tutorials for it.
I'd recommend just diving in.
For example here is some code for NHunspell, which is just the .net version. The code below is just the basic usage but should still be useful for someone getting started.
You can download dictionaries from the Open Office repository
//affPath = path to the .aff file
//dictPath = path to the .dic file
// create and load your hunspell object
NHunspell.Hunspell hunspell = new NHunspell.Hunspell(affPath, dicPath);
// want to add a word that is not part of the base dictionary? Sure, we can do that.
hunspell.Add("stackoverflow");
//lets check if a word is valid
bool isValid = hunpsell.Spell("stackoverflowed");
if(!isValid)
{
//lets get some suggestions for this word
List<String> suggestions = hunspell.Suggest("stackoverflowed");
...do stuff with your list of suggestions
}

Related

Switch to the another language on the same page?

I am trying to add a language changer for Middleman and it's not generating the correct link. My default and root is English.
url_for("/#{current_page.path}", locale: :ja)
I would expect the equivalent for the current page in JA which is the same URL with JA prepended. Does anyone know how to fix this?
I'm a middleman beginner, but after doing a bunch of Googling it seems like this is a fairly common issue. I've tried to look through the middleman sources to see if I could find a solution, but I've been unable. I'm kinda disappointed about this, because it looks like middleman has first-class support for localizations. Being unable to easily link from one to another seems like a surprising omission.
What I've done is make a little helper that can swap localizations in paths, if needed.
def change_locale_in_path(path, locale)
locale_prefix = I18n.locale
path.gsub(/^#{locale_prefix}/, locale.to_s)
end
This isn't a great solution, though. It will need to be adjusted if you change the i18n :path, and won't work unless you mount_at_root: false. But, it worked well enough for me to move on. I really would love to see a better solution.
I found a few GitHub issues that seem to reference this problem. Here's one.
I am using the following helper to generate a URL for the current page in a different language. It was originally based on this gist, and then tweaked it a bit so that it works regardless of whether mount_at_root is used.
def current_url_for_locale(loc)
url_regex = /\A\/(?:(#{I18n.available_locales.join('|')})\/)?/
locale_root = url_for('/', locale: loc)
current_page.url.gsub(url_regex, '').blank? ?
locale_root :
current_page.url.gsub(url_regex, locale_root)
end

Code Editor using ANTLR

I'm in the process of writing a code editor for a custom language. We're using ANTLR for the lexer and parser, and CodeMirror for the editor framework (running in a browser).
I can do some basic things like syntax coloring of keywords, as well as providing rudimentary code completion.
What I'm finding is that the user is frequently in the middle of editing something, so the ANTLR parser is not very useful since the current input stream is not fully parseable (and often leads ANTLR down the wrong path due to an incomplete input stream).
Therefore, I'm using the token stream to figure out what's going on and attempt to provide context-sensitive help.
I'm wondering if anyone can provide some guidance around using ANTLR as part of a code editor. Am I on the right track using the token stream instead of the parse tree?
Can the ANTLR API be leveraged to do things like looking ahead for tokens to figure out the overall context of what the user is currently editing?
Sorry if this is kind of vague. Just getting started on this project. :-)
Thanks for any help.
I find ANTRL great for syntax checking and easy details retrieval for valid input. For code completion however you have a different scenario. As you found out already the parser can often not give you good answers, because the input is not valid while the user is typing. Bart has linked to an answer where Sam described that he implemented a great solution using ANTLR 4, but unfortunately doesn't describe how.
But even if you can get the parser to give you a set of expected tokens, what are you going to make out of it? What do you wanna show if, say, an identifier is expected? That can be anything, like a class member, a var name etc. I don't believe this is the answer, hence I developed an own solution which I describe here: Universal Code Completion using ANTLR. This is for ANTLR 3, but can certainly be made working with 4 as well.
This article also contains several links to (C++) source code that shows how code completion is implemented in my application. It's amazing how simple the implementation is, after all, but still delivers very precise results.
Update
Meanwhile I developed a solution for ANTLR4 too, called [antlr4-c3][2]. This is a Typescript solution but comes with translations to [Java][3] and [C++][4].
If someone is interested in the integration of Codemirror 6 and Antlr4 grammar,
you can find an example on github page.
The main idea is here:
token: (stream, state) => {
// getting tokens for the current stream.string, using antlr4 TokenStream
const tokens = getTokensForText(stream.string);
// getting the next token
const nextToken = tokens.filter(t => t.startIndex >= stream.pos)[0];
// matching the next token in current stream
if (stream.match(nextToken.text)) {
let valueClass = getStyleNameByTag(tags.keyword);
switch (nextToken.type) {
case ...:
valueClass = getStyleNameByTag(tags.string);
break;
...
default:
valueClass = getStyleNameByTag(tags.keyword);
break;
}
return valueClass;
} else {
stream.next();
return null;
}
}

Inno Setup Pascal Script documentation

I started to use Inno Setup as I thought the Pascal Scripting would make it a lot easier for me to do custom stuff, compared to NSIS. However, it seems that there is no documentation anywhere on the Web? The official Wiki has been deleted and I can't find any API documentation. There was an earlier question (3 years-old, an eternity!) which ended in the sad statement that nothing existed.
So far I was able to get help (mostly on Stackoverflow ;-)) each time I wanted to do something specific but I don't want to go accross forums each time I want to do something. My problem right now is to create a directory if it doesn't exist, and I haven't find anyone asking this question yet. So I'm asking. If you know how to do it, can you please tell me (how to do it ;-)) and where you learnt it?
Thanks!
Pascal script syntax is very close to the Pascal/Delphi syntax, so you have a lot of documentation in the Delphi DocWiki and Free pascal documentation about it.
The best place I know about inno-setup specific pascal script function support is the PascalScript section in the Inno Setup Help File, the most relevant sections are:
Support Functions Reference
Support Class Reference
Using DLLs
As for your last question, take a look at this:
var
DocPath: string;
DirPath: string;
begin
DocPath := ExpandConstant('{userdocs}');
DirPath := DocPath + '\ISTest';
if not DirExists(DirPath) then
begin
if not CreateDir(DirPath) then
MsgBox(SysErrorMessage(DLLGetLastError), mbError, mb_Ok);
end;
end;
Where I learned it? I'm a Delphi developer, and the aim of pascal script is to be close to Delphi, so I think I really learned it by learning Delphi. Nowadays, before to take a look at the documentation, I try to do what I want to do a la Delphi, and if I fail doing so, I resort to documentation as a last resource.

What is the best way to save/retrieve array in iOS PG

i have an array of results based on calculation of other arrays of texts entered by the user.
i want to save the array as user clicks on "save results" button.
So i want to know what is the best way to do this.....NSUserDefaults or Databsase, or PList or
and how to save the array by that way.
Actually i have to use NSUserDefaults for that according to my project need
Please help me..
Look into Core Data. It's performant, typically uses less memory than other options, gives you persistence for free.
There are lots of references on line that can help you get started. Try this article by Ray Wenderlich as a start:
http://www.raywenderlich.com/934/core-data-tutorial-getting-started
A Google search can give you many more.
I usually just write the array to file
using
[array writeToFile:myOutputFile atomically:YES];
Here is a reference link.
http://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/NSArray.html#//apple_ref/doc/uid/20000137-BABCGEFF
you can also load them from file with
[array initWithContentsOfFile:myInputFile];
here is another reference link
http://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/NSArray.html#//apple_ref/doc/uid/20000137-CBHBDFEE
just make sure that the output file is located in a writable location for your application.
Note
Normally a good starting point on an object is to get a brief overview of the functions for that object so you know what that object can accomplish.
Hope this helps.

how to get knowing more about a class behaviour without looking at its manual?(a fundamental question about how to dive more into OOP)

I'm practicing OOP for 2 years (for real) and I know how to consume objects and packages and I'm developing stuffs mostly using C# .
but I have a problem with consuming unknown objects and packages as an instance :
for now I am working on an enterprise like website and for part of our job we need to consume RSS. I decided to use "System.Xml.Xpath"
and my real problem is:
for using system.xml.xpath I should look at manual and read it carefully and I don't want to do that every time.A plain example of that is like following code :
XPathDocument xp = new XPathDocument(sites[2]);
XPathNavigator nav = xp.CreateNavigator();
XPathNodeIterator it = nav.Select(xpath3);
foreach (XPathNavigator n in it)
{
//get elements here
}
//another way of iterating elements is
while(it.movenext())
{
//it.current.Value;
}
for the "foreeach" part I got it from MSDN manual and I guess I could get this simple fact by looking at class structure.
but I don't know which structure I should look.
I know how to read tooltips and I'm familiar with things like : [] / collection / enum /generic / Ienumerable / Idisposable etc...
but I think there is something about reading class behaviors and I'm missing that part.
for make it more lucid :
I know whenever we have a class that inherited from IEnumerable so we can use foreach statement against that class to iterate it through
my real problem is I think classes are self described enough to not to look at manuals all the time but I don't know how/where to read those descriptions of classes so I need your advice to get more familiar with how to reading classes without looking at manuals.
best regards.
Classes can (and should) be documented with source code comments, and in many languages you can generate API documentation from these comments (in HTML, XML or other format). In Java it is called Javadoc; I don't know the C# term. If this is what you call "manual", then this is your primary source of information. Other than reading the source code comments and the code itself (which you often don't have access to, especially in the MS universe). If you don't find enough information in the API documentation, you can always try googling for more explanation, tutorials or usage examples.
Hope this helps; I am not entirely sure I understood your question though. If this is not the answer you are looking for, please clarify.