Skip to content

Commit

Permalink
Merge pull request #2 from biodiv-platform/feat-text-parse
Browse files Browse the repository at this point in the history
feat: ✨ added text parse on api
  • Loading branch information
harshzalavadiya committed Nov 15, 2021
2 parents 2a911b3 + 766cbb5 commit c2ec897
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions main.go
Expand Up @@ -64,17 +64,23 @@ func downloadFile(URL string) (string, error) {
return tmpFile, nil
}

// Run document through gnfinder
// find document and extract text from it
func parseDocument(filePath string) string {

txt, err := docconv.ConvertPath(filePath)
if err != nil {
log.Fatal(err)
}

return parseText(txt.Body)
}

// parse names from text through gnfinder
func parseText(txt string) string {

cfg := config.New()
gnf := gnfinder.New(cfg, dict.LoadDictionary(), nlp.BayesWeights())
output := gnf.Find("", txt.Body)
output := gnf.Find("", txt)

return output.Format(gnfmt.PrettyJSON)
}
Expand All @@ -85,6 +91,11 @@ func server(serverPort string) {

app.Get("/parse", func(c *fiber.Ctx) error {
fullFilePath := c.Query("file")
queryText := c.Query("text", "_")

if queryText != "_" {
return c.Type("json").SendString(parseText(queryText))
}

_, err := url.ParseRequestURI(fullFilePath)
if err != nil {
Expand Down

0 comments on commit c2ec897

Please sign in to comment.