GithubHelp home page GithubHelp logo

Comments (6)

catarinarurbano avatar catarinarurbano commented on July 17, 2024

Hi,

I have exactly the same error when running the algorithms in the Jupyter notebook, did you already solve this problem? It seems impossible to make it work.

from spmf-py.

LoLei avatar LoLei commented on July 17, 2024

Apparently the file must be closed on Windows before it can be renamed. Try editing the code here yourself. (Install the package via pip install -e . --user from within the cloned git repository to be able to edit the code and have the changes reflected in the installed package immediately.)

If you get it to work you can open a pull request to have your fix merged and released as a new version.

Otherwise I'll push a change myself, but can't say when I'll be able to, also I can't test it on Windows myself.

from spmf-py.

handychimp avatar handychimp commented on July 17, 2024

Sorry, I should have mentioned: I'd found it was the renaming whilst still open that was the problem too, so instead I wrote the input to a file and called SPMF with a standard input file instead. Have had no further issues when using this method.

It's not required for me to use the temp file, so now I have this code I'm sticking with it for my project. There's no rush needed on a fix. :)

As a question more out of curiosity: once you have to close the temp file, do you not lose any runtime benefit that existed from keeping the stream open? I thought about trying to do it with temp files, but figured if I have to close and reopen the stream, it no longer matters if the input is a temp file or a standard file any more?

Thanks for looking into it!

from spmf-py.

LoLei avatar LoLei commented on July 17, 2024

Great that a workaround exists, thanks for letting others know.

As to your question, I think I just used the tempfile module for convenience. I'm not aware of any performance differences.

from spmf-py.

handychimp avatar handychimp commented on July 17, 2024

Hi,

I have exactly the same error when running the algorithms in the Jupyter notebook, did you already solve this problem? It seems impossible to make it work.

I have a notification in my email that asked if i could share the code, but it's not in the thread anymore? I'm not sure if it is what you need but, and not necessarily the most elegant but i put them below. They return strings that you will need to write to a text file.

This one is for taking a nested list of sequences, i.e. a list of sequences that are themselves nested lists of form: seq = [ [1, 2, 3] , [1, 5] , [9] ]

def sequence_to_spmf_format(sequence_lists):
    """takes a nested list input and returns a string in SPMF format"""
    seq_spmf = ""
    for seq in sequence_lists:
        for item_set in seq:
            for item in item_set:
                seq_spmf += str(item) + ' '
            seq_spmf += str(-1) + ' '
        seq_spmf += str(-2) + '\n'

    return seq_spmf

In this one, each pattern is a list of strings. I believe most the SPMF algorithms assume no duplicates in the pattern and that each pattern is sorted, so i did that in this function too.

def pattern_to_spmf_format(pattern_list):
    """takes a list of patterns and returns a string in SPMF format"""
    pat_spmf = ""
    for pat in pattern_list:
        p = [str(x) for x in list(set(pat))]
        p.sort()
        pat_spmf += " ".join(p) + "\n"
            
    return pat_spmf

Hope that helps.

from spmf-py.

SantoshKumarRaju avatar SantoshKumarRaju commented on July 17, 2024

I was also facing the same issue with temp file on Windows platform, and what I did was to close the temp file before the renaming happens. This seems to have resolved the issue, the updated code is shown below:

    def write_temp_input_file(self, input_text, file_ending):
        tf = tempfile.NamedTemporaryFile(delete=False)
        tf.write(bytes(input_text, 'UTF-8'))
        name = tf.name
        tf.close() # did tf.close before renaming.
        os.rename(name, name + file_ending)
        return name + file_ending

from spmf-py.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.