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

Serialization & Deserialization #25

Closed
kafechew opened this issue Mar 15, 2015 · 7 comments
Closed

Serialization & Deserialization #25

kafechew opened this issue Mar 15, 2015 · 7 comments
Assignees

Comments

@kafechew
Copy link

I'm having issues with the Serialisation and Deserialisation for combination of limdu + serialization npm packages.

Normally, we will serialise into a .json file.
Using serialize.toString(), I don't where is the serialized .json file.

Q1. Maybe limdu/serialization will not generate the .json file?

Anyone can enlighten?
Thanks.

@erelsgl
Copy link
Owner

erelsgl commented Mar 15, 2015

Hi Kai,

The function serialize.toString does not automatically generate a json file. It only returns a string.

To save the string to a file, you can use the standard writeFile or writeFileSync function of the fs library, see here:
https://nodejs.org/api/all.html#all_fs_writefile_filename_data_options_callback

For example:

var fs = require('fs');  
var classifierString = serialize.toString(intentClassifier, newClassifierFunction);
fs.writeFileSync("myFileName.json", classifierString);

@kafechew
Copy link
Author

You're so cool!

Let's say I had saved the string to "myFileName.json" as suggested...
and send into remote server folder, "/myFolder".
How to initialize the deserialization?

My guess:

var intentClassifierCopy = serialize.fromString(intentClassifierString, myFolder/myFileName.json);

Am I right?

Thanks again!

@erelsgl
Copy link
Owner

erelsgl commented Mar 15, 2015

In order to deserialize, you first have to read the string from the file, like this:

var intentClassifierString = fs.readFileSync("myFolder/myFileName.json");
var intentClassifierCopy = serialize.fromString(intentClassifierString, __dirname);

@erelsgl erelsgl self-assigned this Mar 15, 2015
@kafechew
Copy link
Author

Working great!
I had migrated from natural to limdu!
Thank you very much!

@kafechew
Copy link
Author

@erelsgl
The above, we will store the .json files as local files in the remote server.
What if the .json file is an external file, not a local file?
Instead of moving the files to remote server, can the remote server directly call the .json from the original server?

Can we deserialise the external .json (http://anotherweb.com/json/myFileName.json) ?

My guess:

var __dirname = "http://anotherweb.com/json";
var intentClassifierString = fs.readFileSync("myFileName.json");
var intentClassifierCopy = serialize.fromString(intentClassifierString, __dirname);

Can you confirm that?
Thanks in advanced.

@kafechew kafechew reopened this Apr 27, 2015
@erelsgl
Copy link
Owner

erelsgl commented Apr 28, 2015

Hi Kai,

I think readFileSync works only with local files.

To download a remote file, try the suggestions here:
http://stackoverflow.com/questions/11944932/how-to-download-a-file-with-node-js

On Mon, Apr 27, 2015 at 5:29 PM, Kai Chew notifications@github.com wrote:

Reopened #25 #25.


Reply to this email directly or view it on GitHub
#25 (comment).

@kafechew
Copy link
Author

@erelsgl
You're right. Just solved through alike method as you suggested, i.e. xhr
Things are interesting now!
Thanks again!! :-)

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

No branches or pull requests

2 participants