mirror of
https://github.com/ru-de/faq.git
synced 2024-11-22 18:32:19 +00:00
spell-checker
This commit is contained in:
parent
516da15135
commit
e7b7090f42
26
.travis.sh
Normal file
26
.travis.sh
Normal file
@ -0,0 +1,26 @@
|
||||
#!/bin/bash
|
||||
|
||||
go build spell-checker.go
|
||||
|
||||
EXIT_CODE=0
|
||||
|
||||
git diff HEAD^ --name-only > changed_files
|
||||
|
||||
while read FILE; do
|
||||
echo -n "Проверка файла $FILE на опечатки... ";
|
||||
|
||||
OUTPUT_RU=$(cat "$FILE" | hunspell -d ru_RU | ./spell-checker);
|
||||
RU_EXIT_CODE=$?
|
||||
OUTPUT_EN=$(cat "$FILE" | hunspell -d en_US | ./spell-checker);
|
||||
EN_EXIT_CODE=$?
|
||||
|
||||
if [ $RU_EXIT_CODE -ne 0 ] || [ $EN_EXIT_CODE -ne 0 ]; then
|
||||
EXIT_CODE=1;
|
||||
echo "ошибка";
|
||||
echo "$OUTPUT_RU\n$OUTPUT_EN" | sort -n -k1,4;
|
||||
else
|
||||
echo "пройдена";
|
||||
fi
|
||||
done < changed_files
|
||||
|
||||
exit $EXIT_CODE
|
59
spell-checker.go
Normal file
59
spell-checker.go
Normal file
@ -0,0 +1,59 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"bufio"
|
||||
)
|
||||
|
||||
|
||||
type TypeResult struct {
|
||||
results []Result
|
||||
}
|
||||
|
||||
type Result struct {
|
||||
line int
|
||||
word string
|
||||
}
|
||||
|
||||
func main() {
|
||||
scanner := bufio.NewScanner(os.Stdin)
|
||||
types := parseHunspellOutput(scanner);
|
||||
|
||||
_, ok := types["&"]
|
||||
|
||||
if ok {
|
||||
for _, result := range types["&"].results {
|
||||
fmt.Println("Строка " + fmt.Sprintf("%v", result.line) + ":" + result.word)
|
||||
}
|
||||
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func parseHunspellOutput(scanner *bufio.Scanner) map[string]*TypeResult {
|
||||
line := 1;
|
||||
types := make(map[string]*TypeResult)
|
||||
|
||||
scanner.Scan()
|
||||
|
||||
for scanner.Scan() {
|
||||
text := scanner.Text()
|
||||
|
||||
if text == "" {
|
||||
line++;
|
||||
} else {
|
||||
resultType := text[0:1]
|
||||
typeResult, ok := types[resultType]
|
||||
|
||||
if !ok {
|
||||
typeResult = &TypeResult{}
|
||||
types[resultType] = typeResult
|
||||
}
|
||||
|
||||
typeResult.results = append(typeResult.results, Result{line: line, word: text[1:]})
|
||||
}
|
||||
}
|
||||
|
||||
return types
|
||||
}
|
Loading…
Reference in New Issue
Block a user