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

Replace mode #22

Merged
merged 1 commit into from
Apr 4, 2022
Merged

Replace mode #22

merged 1 commit into from
Apr 4, 2022

Conversation

wzwietering
Copy link
Collaborator

This PR implements replace mode without a knowledge base. You can run replace mode using:

stack run -- team-proj-abbr-cli replace --input=data/test_file.txt --out=test.txt -k data/kb_example.csv

Copy link
Collaborator

@dee-me-tree-or-love dee-me-tree-or-love left a comment

Choose a reason for hiding this comment

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

Hey @wzwietering really cool stuff. This is really starting to take shape! Thanks a lot 👍 I've left a few remarks, but it's up for a discussion, let's catch up on it? I'll review the other PR in a bit

returnOutput :: Maybe FilePath -> String -> IO ()
returnOutput f = case f of
Nothing -> error "No output file found"
Just s -> writeFile s
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd suggest we keep all the IO logic (something interacting with the OS/file system) to the LibCli to keep the separation of concerns? :) Then for instance, this allows projects to grow naturally when a runtime environment is changed (say to REST API instead of CLI or so)

s <- readFile f
returnOutput (out c) (decode $ mapParseStructure getKnowledgeBase $ doParse s)
-- Impossible case because of the mockCliHandler
replaceMode _ = undefined
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is interesting! My thought was that we could actually implement this in the mockCliHandler's pattern matching case. Then we'd for instance write something like this:

mockCliHandler c@CS.Replace {out=o} = do  -- can be extended with other arguments `{out=o, kb=kb ...}`
  case input c of
      Nothing -> error "No input file was found"
      Just f -> handle f
  where
    handle f = do
      s <- readFile f 
      returnOutput o (decode $ mapParseStructure getKnowledgeBase $ doParse s) 
    -- Which could also be a separate _total_ function on strings: `handle :: String -> IO ()`.
    -- Or even further, this could be an instance of the type class... if we really wanna go full fancy?
    --     class Handler .... where
    --         handle :: String -> IO ()
    --      ...
    --     instance Handler CS.Replace where
    --         handle = ...
    -- and then we don't even need to make all the separate functions so to say... 

Copy link
Collaborator

Choose a reason for hiding this comment

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

Generally, this would allow us to avoid functions that can return undefined -- which might end up error prone. WDYT?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, the pattern mathcing is covered in #23, so we can avoid the undefined

@@ -0,0 +1 @@
Hello world. This file is written to test the expansions of kb_example.csv. We should see that hello is expanded to hello. This is a theorem, which we cannot proof. No lemma or axiom can be used, because this is not a scientific theorem.
Copy link
Collaborator

Choose a reason for hiding this comment

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

awesome! this is really nice 👍

@@ -0,0 +1 @@
Hello world. This file is written to test the expansions of kb_example.csv. We should see that @@hl is expanded to hello. This is a @@thm, which we cannot @@prf. No @@lmm or @@ax can be used, because this is not a scientific theorem.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Great job on adding the test data! That'll be super useful!

Nothing -> error "No input file was found"
Just f -> do
s <- readFile f
returnOutput (out c) (decode $ mapParseStructure getKnowledgeBase $ doParse s)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks really nice and clear which steps happen after which, really cool :)

import LibCore.Models (Keyword)

type KnowledgeBaseStructure = Map Keyword Keyword

getKnowledgeBase :: KnowledgeBaseStructure
getKnowledgeBase = undefined
getKnowledgeBase = empty
Copy link
Collaborator

Choose a reason for hiding this comment

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

Fair enough 👍

Copy link
Collaborator

@dee-me-tree-or-love dee-me-tree-or-love left a comment

Choose a reason for hiding this comment

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

Decided to go with this for now :) 👍 Further improvements can be made further on 👍

@wzwietering wzwietering merged commit ce753e7 into main Apr 4, 2022
@wzwietering wzwietering deleted the wilmer/cli_integration branch April 4, 2022 20:34
cad0p added a commit that referenced this pull request Apr 4, 2022
* Replace mode

* first commit, add cassava import

* defaultKB renaming

* had to add this to install brittany

* add directory as dependency

* the get KB function now receives the filepath
(assumed to be correct)

* pre-existing typo

* my adaptation to get the KB in replaceMode

* rename to fp to better represent a FilePath
and not a File

* added source of doesFileExist trick

* added dependencies bytestring and vector

* ** does not work ** getKnowledgeBase idea

* it works! needs cleanup

* cleanup and docs

* docs

Based on Wilmer Zwietering <[email protected]> for #22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants