<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to Code Snippets</title><link>https://sourceforge.net/p/jinsect/wiki/Code%2520Snippets/</link><description>Recent changes to Code Snippets</description><atom:link href="https://sourceforge.net/p/jinsect/wiki/Code%20Snippets/feed" rel="self"/><language>en</language><lastBuildDate>Tue, 25 Aug 2015 12:01:41 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/jinsect/wiki/Code%20Snippets/feed" rel="self" type="application/rss+xml"/><item><title>Code Snippets modified by George Giannakopoulos</title><link>https://sourceforge.net/p/jinsect/wiki/Code%2520Snippets/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v1
+++ v2
@@ -1,17 +1,93 @@
 **Overview**
 The main tasks one usually needs to perform using n-gram graphs are:
 * Create an n-gram graph from a string
+* Output a graph as a [DOT](http://www.graphviz.org/doc/info/lang.html) string
 * Create an n-gram graph from a file
 * Compare two graphs, extracting their similarity
 * Merge two (or more) graphs
-* Output a graph as a [DOT](http://www.graphviz.org/doc/info/lang.html) file
 * Save and load a graph

 We will provide samples in the following sections, tackling the above problems. 

-**Create an n-gram graph**
+**Create an n-gram graph from a string**
+
 ~~~~~~
-String sTmp = "Hello graph!"; // The string we want to represent
-DocumentNGramGraph dngGraph = new DocumentNGramGraph(); // The default document n-gram graph, with min n-gram size and max n-gram size set to 3, and the dist parameter set to 3.
-dngGraph.setDataString(sTmp); // Create the graph
+:::java
+...
+import gr.demokritos.iit.jinsect.documentModel.representations.DocumentNGramGraph;
+
+...
+ // The string we want to represent
+ String sTmp = "Hello graph!";
+ 
+ // The default document n-gram graph, with min n-gram size and max n-gram size set to 3, and the dist parameter set to 3.
+DocumentNGramGraph dngGraph = new DocumentNGramGraph(); 
+
+// Create the graph
+dngGraph.setDataString(sTmp); 
 ~~~~~~
+
+**Output a graph as a [DOT](http://www.graphviz.org/doc/info/lang.html) string**
+
+~~~~~~
+:::java
+        /* The following command gets the first n-gram graph level (with the minimum n-gram
+        size) and renders it, using the utils package, as a DOT string */
+        System.out.println(utils.graphToDot(dngGraph.getGraphLevel(0), true));
+~~~~~~
+
+**Create an n-gram graph from a file**
+
+~~~~~~
+:::java
+...
+import gr.demokritos.iit.jinsect.documentModel.comparators.NGramCachedGraphComparator;
+import gr.demokritos.iit.jinsect.documentModel.representations.DocumentNGramGraph;
+import gr.demokritos.iit.jinsect.structs.GraphSimilarity;
+import gr.demokritos.iit.jinsect.utils;
+import java.io.IOException;
+...
+        // The filename of the file the contents of which will form the graph
+        String sFilename = "file.txt";
+        DocumentNGramGraph dngGraph = new DocumentNGramGraph(); 
+        // Load the data string from the file, also dealing with exceptions
+        try {
+            dngGraph.loadDataStringFromFile(sFilename);
+        } catch (IOException ex) {
+            ex.printStackTrace();
+        }
+~~~~~~
+
+**Compare two graphs, extracting their similarity**
+
+~~~~~~
+:::java
+...
+import gr.demokritos.iit.jinsect.documentModel.comparators.NGramCachedGraphComparator;
+import gr.demokritos.iit.jinsect.documentModel.representations.DocumentNGramGraph;
+import gr.demokritos.iit.jinsect.structs.GraphSimilarity;
+import gr.demokritos.iit.jinsect.utils;
+import java.io.IOException;
+...
+
+        String sTmp = "Hello graph!";
+        DocumentNGramGraph dngGraph = new DocumentNGramGraph(); 
+        dngGraph.setDataString(sTmp);
+        String sTmp2 = "Hello other graph!";
+        DocumentNGramGraph dngGraph2 = new DocumentNGramGraph(); 
+        dngGraph2.setDataString(sTmp2);
+         // Create a comparator object
+         NGramCachedGraphComparator ngc = new NGramCachedGraphComparator();
+         // Extract similarity
+         GraphSimilarity gs = ngc.getSimilarityBetween(dngGraph, dngGraph2);
+         // Output similarity (all three components: containment, value and size)
+         System.out.println(gs.toString());
+
+~~~~~~
+
+**Merge two graphs**
+Will be added soon (I hope).
+
+
+**Save and load a graph**
+Same as above.
&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">George Giannakopoulos</dc:creator><pubDate>Tue, 25 Aug 2015 12:01:41 -0000</pubDate><guid>https://sourceforge.net758012947524913e5f9436e100625b3530debf6c</guid></item><item><title>Code Snippets modified by George Giannakopoulos</title><link>https://sourceforge.net/p/jinsect/wiki/Code%2520Snippets/</link><description>&lt;div class="markdown_content"&gt;&lt;p&gt;&lt;strong&gt;Overview&lt;/strong&gt;&lt;br/&gt;
The main tasks one usually needs to perform using n-gram graphs are:&lt;br/&gt;
&lt;em&gt; Create an n-gram graph from a string&lt;br/&gt;
&lt;/em&gt; Create an n-gram graph from a file&lt;br/&gt;
&lt;em&gt; Compare two graphs, extracting their similarity&lt;br/&gt;
&lt;/em&gt; Merge two (or more) graphs&lt;br/&gt;
&lt;em&gt; Output a graph as a &lt;a class="" href="http://www.graphviz.org/doc/info/lang.html" rel="nofollow"&gt;DOT&lt;/a&gt; file&lt;br/&gt;
&lt;/em&gt; Save and load a graph&lt;/p&gt;
&lt;p&gt;We will provide samples in the following sections, tackling the above problems. &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Create an n-gram graph&lt;/strong&gt;&lt;br/&gt;
    String sTmp = "Hello graph!"; // The string we want to represent&lt;br/&gt;
    DocumentNGramGraph dngGraph = new DocumentNGramGraph(); // The default document n-gram graph, with min n-gram size and max n-gram size set to 3, and the dist parameter set to 3.&lt;br/&gt;
    dngGraph.setDataString(sTmp); // Create the graph&lt;/p&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">George Giannakopoulos</dc:creator><pubDate>Tue, 25 Aug 2015 11:11:56 -0000</pubDate><guid>https://sourceforge.netdc4d6ef686411f817155b32beb9d70a6d88d039e</guid></item></channel></rss>