-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Victor Rodriguez Doncel
committed
Jul 10, 2015
1 parent
924bd1e
commit b85b975
Showing
7 changed files
with
86 additions
and
33 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,102 @@ | ||
package pgn2rdf.chess; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.PrintWriter; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import javax.xml.parsers.DocumentBuilderFactory; | ||
import org.apache.jena.riot.Lang; | ||
import org.apache.log4j.BasicConfigurator; | ||
import org.apache.commons.cli.BasicParser; | ||
import org.apache.commons.cli.CommandLine; | ||
import org.apache.commons.cli.CommandLineParser; | ||
import org.apache.commons.cli.HelpFormatter; | ||
import org.apache.commons.cli.Options; | ||
import org.apache.commons.cli.Option; | ||
import org.apache.commons.io.FileUtils; | ||
import org.apache.log4j.Logger; | ||
import org.apache.log4j.varia.NullAppender; | ||
import pgn2rdf.files.GameUploader; | ||
import pgn2rdf.files.RDFStore; | ||
|
||
/** | ||
* http://stackoverflow.com/questions/15906842/solr-4-2-1-sslinitializationexception | ||
* | ||
* Important for debugging with Glassfish and Netbeans: http://www.javahispano.org/java-ee/post/2433388 | ||
* Important for debugging with Glassfish and Netbeans: | ||
* http://www.javahispano.org/java-ee/post/2433388 | ||
* | ||
* @author Victor | ||
*/ | ||
public class Main { | ||
|
||
public static boolean initialized = false; | ||
|
||
public static void main(String[] args) throws IOException { | ||
BasicConfigurator.configure(); | ||
System.out.println("Hello world"); | ||
String input = new String(Files.readAllBytes(Paths.get("samples/test.pgn"))); | ||
String rdf = PGNProcessor.getRDF(input, Lang.TTL); | ||
System.out.println(rdf); | ||
Logger.getRootLogger().removeAllAppenders(); | ||
Logger.getRootLogger().addAppender(new NullAppender()); | ||
|
||
StringBuilder sb = new StringBuilder(); | ||
CommandLineParser clparser = null; | ||
CommandLine cl = null; | ||
try { | ||
Options options = new Options(); | ||
options.addOption("help", false, "shows this help (Help)"); | ||
options.addOption("add", true, "Transforms, expands and uploads a PGN file"); | ||
options.addOption("transform", true, "Transforms, a PGN file"); | ||
options.addOption("out", true, "Specifies output file"); | ||
options.addOption("count", false, "Counts the number of games"); | ||
clparser = new BasicParser(); | ||
cl = clparser.parse(options, args); | ||
if (cl.hasOption("help")) { | ||
System.out.println("RDFChess command line tool"); | ||
new HelpFormatter().printHelp(Main.class.getCanonicalName(), options); | ||
} | ||
if (cl.hasOption("count")) { | ||
int total =RDFStore.countGames(); | ||
System.out.println(total); | ||
} | ||
if (cl.hasOption("add")) { | ||
String sfile = cl.getOptionValue("add"); | ||
GameUploader.uploadPGN(sfile); | ||
} | ||
if (cl.hasOption("transform")) { | ||
String sfile = cl.getOptionValue("transform"); | ||
String sout = cl.getOptionValue("output"); | ||
String input = new String(Files.readAllBytes(Paths.get(sfile))); | ||
String rdf = PGNProcessor.getRDF(input, Lang.TTL); | ||
if (sout.isEmpty()) { | ||
System.out.println(rdf); | ||
} else { | ||
FileUtils.writeStringToFile(new File(sout), rdf); | ||
} | ||
} | ||
} catch (Exception e) { | ||
System.err.println("error"); | ||
} | ||
|
||
} | ||
|
||
|
||
public static void init() throws Exception { | ||
System.out.println("Initializing RDFChess"); | ||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); | ||
/*if (initialized == true) { | ||
return; | ||
} | ||
return; | ||
} | ||
SSLContextBuilder builder = new SSLContextBuilder(); | ||
builder.loadTrustMaterial(null, new TrustSelfSignedStrategy()); | ||
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory( | ||
builder.build()); | ||
CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory( | ||
sslsf).build(); | ||
SSLContextBuilder builder = new SSLContextBuilder(); | ||
builder.loadTrustMaterial(null, new TrustSelfSignedStrategy()); | ||
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory( | ||
builder.build()); | ||
CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory( | ||
sslsf).build(); | ||
DefaultHttpClient httpClient = new DefaultHttpClient(); | ||
httpClient.getConnectionManager().getSchemeRegistry() | ||
.register(new Scheme("https", 443, | ||
SSLSocketFactory.getSystemSocketFactory())); | ||
initialized = true; | ||
*/ | ||
DefaultHttpClient httpClient = new DefaultHttpClient(); | ||
httpClient.getConnectionManager().getSchemeRegistry() | ||
.register(new Scheme("https", 443, | ||
SSLSocketFactory.getSystemSocketFactory())); | ||
initialized = true; | ||
*/ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters