Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #8, convert hunspell output to spellchecker JSON format #9

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions backend/spellchecker/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.pyc
__pycache__
.idea
libparser/build/*
!libparser/build/Makefile
15 changes: 15 additions & 0 deletions backend/spellchecker/libparser/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 3.2)
project(parsers)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lhunspell")

set(SOURCE_FILES
parsers/latexparser.cxx
parsers/latexparser.hxx
parsers/textparser.cxx
parsers/textparser.hxx
parser.cpp)

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/parsers)

add_library(parser SHARED ${SOURCE_FILES})
238 changes: 238 additions & 0 deletions backend/spellchecker/libparser/build/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 3.6

# Default target executed when no arguments are given to make.
default_target: all

.PHONY : default_target

# Allow only one "make -f Makefile2" at a time, but pass parallelism.
.NOTPARALLEL:


#=============================================================================
# Special targets provided by cmake.

# Disable implicit rules so canonical targets will work.
.SUFFIXES:


# Remove some rules from gmake that .SUFFIXES does not remove.
SUFFIXES =

.SUFFIXES: .hpux_make_needs_suffix_list


# Suppress display of executed commands.
$(VERBOSE).SILENT:


# A target that is always out of date.
cmake_force:

.PHONY : cmake_force

#=============================================================================
# Set environment variables for the build.

# The shell in which to execute make rules.
SHELL = /bin/sh

# The CMake executable.
CMAKE_COMMAND = /usr/bin/cmake

# The command to remove a file.
RM = /usr/bin/cmake -E remove -f

# Escaping for special characters.
EQUALS = =

# The top-level source directory on which CMake was run.
CMAKE_SOURCE_DIR = /home/tener/git/papeeria/backend/spellchecker/libparser

# The top-level build directory on which CMake was run.
CMAKE_BINARY_DIR = /home/tener/git/papeeria/backend/spellchecker/libparser/build

#=============================================================================
# Targets provided globally by CMake.

# Special rule for the target edit_cache
edit_cache:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake cache editor..."
/usr/bin/ccmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
.PHONY : edit_cache

# Special rule for the target edit_cache
edit_cache/fast: edit_cache

.PHONY : edit_cache/fast

# Special rule for the target rebuild_cache
rebuild_cache:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..."
/usr/bin/cmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
.PHONY : rebuild_cache

# Special rule for the target rebuild_cache
rebuild_cache/fast: rebuild_cache

.PHONY : rebuild_cache/fast

# The main all target
all: cmake_check_build_system
$(CMAKE_COMMAND) -E cmake_progress_start /home/tener/git/papeeria/backend/spellchecker/libparser/build/CMakeFiles /home/tener/git/papeeria/backend/spellchecker/libparser/build/CMakeFiles/progress.marks
$(MAKE) -f CMakeFiles/Makefile2 all
$(CMAKE_COMMAND) -E cmake_progress_start /home/tener/git/papeeria/backend/spellchecker/libparser/build/CMakeFiles 0
.PHONY : all

# The main clean target
clean:
$(MAKE) -f CMakeFiles/Makefile2 clean
.PHONY : clean

# The main clean target
clean/fast: clean

.PHONY : clean/fast

# Prepare targets for installation.
preinstall: all
$(MAKE) -f CMakeFiles/Makefile2 preinstall
.PHONY : preinstall

# Prepare targets for installation.
preinstall/fast:
$(MAKE) -f CMakeFiles/Makefile2 preinstall
.PHONY : preinstall/fast

# clear depends
depend:
$(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1
.PHONY : depend

#=============================================================================
# Target rules for targets named parser

# Build rule for target.
parser: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 parser
.PHONY : parser

# fast build rule for target.
parser/fast:
$(MAKE) -f CMakeFiles/parser.dir/build.make CMakeFiles/parser.dir/build
.PHONY : parser/fast

parser.o: parser.cpp.o

.PHONY : parser.o

# target to build an object file
parser.cpp.o:
$(MAKE) -f CMakeFiles/parser.dir/build.make CMakeFiles/parser.dir/parser.cpp.o
.PHONY : parser.cpp.o

parser.i: parser.cpp.i

.PHONY : parser.i

# target to preprocess a source file
parser.cpp.i:
$(MAKE) -f CMakeFiles/parser.dir/build.make CMakeFiles/parser.dir/parser.cpp.i
.PHONY : parser.cpp.i

parser.s: parser.cpp.s

.PHONY : parser.s

# target to generate assembly for a file
parser.cpp.s:
$(MAKE) -f CMakeFiles/parser.dir/build.make CMakeFiles/parser.dir/parser.cpp.s
.PHONY : parser.cpp.s

parsers/latexparser.o: parsers/latexparser.cxx.o

.PHONY : parsers/latexparser.o

# target to build an object file
parsers/latexparser.cxx.o:
$(MAKE) -f CMakeFiles/parser.dir/build.make CMakeFiles/parser.dir/parsers/latexparser.cxx.o
.PHONY : parsers/latexparser.cxx.o

parsers/latexparser.i: parsers/latexparser.cxx.i

.PHONY : parsers/latexparser.i

# target to preprocess a source file
parsers/latexparser.cxx.i:
$(MAKE) -f CMakeFiles/parser.dir/build.make CMakeFiles/parser.dir/parsers/latexparser.cxx.i
.PHONY : parsers/latexparser.cxx.i

parsers/latexparser.s: parsers/latexparser.cxx.s

.PHONY : parsers/latexparser.s

# target to generate assembly for a file
parsers/latexparser.cxx.s:
$(MAKE) -f CMakeFiles/parser.dir/build.make CMakeFiles/parser.dir/parsers/latexparser.cxx.s
.PHONY : parsers/latexparser.cxx.s

parsers/textparser.o: parsers/textparser.cxx.o

.PHONY : parsers/textparser.o

# target to build an object file
parsers/textparser.cxx.o:
$(MAKE) -f CMakeFiles/parser.dir/build.make CMakeFiles/parser.dir/parsers/textparser.cxx.o
.PHONY : parsers/textparser.cxx.o

parsers/textparser.i: parsers/textparser.cxx.i

.PHONY : parsers/textparser.i

# target to preprocess a source file
parsers/textparser.cxx.i:
$(MAKE) -f CMakeFiles/parser.dir/build.make CMakeFiles/parser.dir/parsers/textparser.cxx.i
.PHONY : parsers/textparser.cxx.i

parsers/textparser.s: parsers/textparser.cxx.s

.PHONY : parsers/textparser.s

# target to generate assembly for a file
parsers/textparser.cxx.s:
$(MAKE) -f CMakeFiles/parser.dir/build.make CMakeFiles/parser.dir/parsers/textparser.cxx.s
.PHONY : parsers/textparser.cxx.s

# Help Target
help:
@echo "The following are some of the valid targets for this Makefile:"
@echo "... all (the default if no target is provided)"
@echo "... clean"
@echo "... depend"
@echo "... edit_cache"
@echo "... rebuild_cache"
@echo "... parser"
@echo "... parser.o"
@echo "... parser.i"
@echo "... parser.s"
@echo "... parsers/latexparser.o"
@echo "... parsers/latexparser.i"
@echo "... parsers/latexparser.s"
@echo "... parsers/textparser.o"
@echo "... parsers/textparser.i"
@echo "... parsers/textparser.s"
.PHONY : help



#=============================================================================
# Special targets to cleanup operation of make.

# Special rule to run CMake to check the build system integrity.
# No rule that depends on this can have commands that come from listfiles
# because they might be regenerated.
cmake_check_build_system:
$(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0
.PHONY : cmake_check_build_system

47 changes: 47 additions & 0 deletions backend/spellchecker/libparser/parser.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include "parsers/latexparser.hxx"
#include <cstring>
#include <iostream>
#include <assert.h>

extern "C" {

struct Token {
char* token;
};

std::string alphabet("qwertzuiopasdfghjklyxcvbnmQWERTZUIOPASDFGHJKLYXCVBNM");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WTF?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I know, but for some reason latexparser needs alphabet as an argument of constructor. textparser (latexparser inherits it) has default constructor, btw, and this is the very string that initializes textparser's wordchar array (some inner stuff, I dunno).
Proof (textparser.cxx:126):
2016-09-01__00 38 57__592x74


LaTeXParser* latex_parser() {
return new LaTeXParser(alphabet.c_str());
}

void delete_parser(LaTeXParser *parser) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it your code as well? Please add author and format the code

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, sure, forgot about that cpp stuff over there

delete parser;
}

void put_line(LaTeXParser* parser, char* line) {
parser->put_line(line);
}

int next_token(LaTeXParser *parser, Token *token) {
parser->set_url_checking(true);
std::string next;
if (parser->next_token(next)) {
token->token = new char[next.size()+1];
std::copy(next.begin(), next.end(), token->token);
token->token[next.size()] = '\0';
return 1;
}
else {
token->token = NULL;
return 0;
}
}

void free_token(Token *token) {
if (token->token) {
delete [] token->token;
}
}
}

Loading