forked from nickthecook/archyve
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support ingesting DOCX files using pandoc
- Loading branch information
Showing
4 changed files
with
25 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module Parsers | ||
class Docx | ||
include BasicTextChunker | ||
|
||
def initialize(document) | ||
@document = document | ||
end | ||
|
||
def text | ||
# NOTE: Using -raw opt causes text to be broken up a lot; but not using raw | ||
# may cause tables to be "pretty" in text which may not be ideal for chunking. | ||
# Not specifying works best for rotated pages, so doing that for now | ||
cmd = 'pandoc -f docx --to=commonmark -' | ||
txt, serr, status = Open3.capture3(cmd, stdin_data: @document.contents, binmode: true) | ||
return txt if status.success? | ||
|
||
Rails.logger.error("Error running '#{cmd}' on DOCX: #{@document.filename}\n#{serr}") | ||
|
||
raise StandardError, "Error converting DPCX to text: #{@document.filename}'" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters