Parses Amazon product metadata contained in the file amazon-meta.txt scraped by Stanford University's SNAP library:
Amazon Metadata Project on SNAP
- Clone the project to your hard drive
- Download amazon-meta.txt.gz from the SNAP library
- Unzip it into the project's
Resources/folder and ensure it is namedamazon-meta.txt - Make sure you are using Java SE 8
- Compile and run
Parser.javato see the parsed data output to your console
You will most likely want to do something other than simply print the data to your console. To output the data according to your own needs, use one of the preconfigured Output-implementing classes in the output package—or make your own! Parsed data is represented as a ProductDTO, which is loosely speaking (sigh programmer semantics...) a Data Transfer Objects. The main type is ProductDTO, but it has children DTOs for multivalued attributes such as reviews. This design was chosen to make mapping to relational databases more conceptually clear.
Here is an example of using the Parser with ConsoleOutput.
import java.io.IOException;
import amazon_product_metadata_parser.Parser;
import amazon_product_metadata_parser.output.ConsoleOutput;
import amazon_product_metadata_parser.output.Output;
public class YourClass {
public static void main(String... args) {
String pathToAmazonMetaFile = "{your path here}";
Output output = new ConsoleOutput();
// Create the Parser object
Parser parser = new Parser(pathToAmazonMetaFile, output);
// Start the parsing process which calls output.createProduct() for each parsed product
try {
parser.parse();
} catch (IOException e) { e.printStackTrace(); }
}
}Because the dataset is so large, the program sends the parsed ProductDTO objects to the designated Output class as it parses them (as opposed to waiting until the end) much like a stream. This avoids trying to keep 548,552 objects in memory! All you need to do is create an object that implements the interface and put what you want to do with each ProductDTO in the createProduct(ProductDTO productDTO) method. Here is an example of the ConsoleOutput object:
import java.io.IOException;
import amazon_product_metadata_parser.dto.ProductDTO;
/**
* Simply prints product data to the console
*/
public class ConsoleOutput implements Output {
@Override
public void open() throws IOException {
// do nothing
}
@Override
public void createProduct(ProductDTO productDTO) throws IOException {
System.out.println(productDTO.toString());
}
@Override
public void close() throws IOException {
// do nothing
}
}The open and close methods will be called before and after parsing, respectively, and are provided in case there are setup or teardown tasks (Output implements java.io.Closeable). If an IOException occurs, parsing will cease.
Currently in development. Connects to your default SQL Server 2012 instance via Windows authentication. If you don't know what an instance is, don't worry about it, but it's usually named "MSSQLSERVER" or "SQLEXPRESS").
- Requires use of the
sqljdbc41.jarlibrary (Microsoft Download) - Requires the
sqljdbc_auth.dll(included with the download from Microsoft described above) be loaded in the JavaVM. The easiest method is to copy the file from eithersqljdbc_4.1\enu\auth\x64\sqljdbc_auth.dllorsqljdbc_4.1\enu\auth\x86\sqljdbc_auth.dlldepending on if your JRE is 32-bit or 64-bit, and place it your JRE'sbinfolder. For example, place the x64 version of the .dll on a 64-bit machine in the:C:\Program Files\Java\jdk1.8.0_31\jre\bin\directory. Make sure to use the appropriate 32-bit or 64-bit version of the.dllto match your JRE. - Requires
SQL Serverservice to be running for your default instance - Requires
SQL Server Browserservice also be running
Feel free to fork this project or submit a pull request.
Please use the issues page for reporting any bugs you encounter.
MIT (see LICENSE)
Rob Wise