Permalink
Browse files

more work on example code for chapter on RDF generation from web page…

…s, Freebase, and DBpedia
  • Loading branch information...
1 parent 553a690 commit 94fa7ee68009d4b794c854d7ceb016a5f58905bd @mark-watson committed Apr 3, 2010
Showing with 11 additions and 10 deletions.
  1. +5 −0 Java_practical_semantic_web.iml
  2. +1 −1 README.rdoc
  3. +1 −4 examples/EntityToD2RHelpers.java
  4. +4 −5 examples/RdfDataGenerationApplication.java
@@ -7,6 +7,11 @@
<facet type="Scala" name="Scala">
<configuration />
</facet>
+ <facet type="JRUBY" name="JRuby">
+ <configuration number="0">
+ <JRUBY_FACET_CONFIG_ID NAME="JRUBY_SDK_NAME" VALUE="" />
+ </configuration>
+ </facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
View
@@ -1,4 +1,4 @@
-= Companion Software examples for the book "Practical Semantic Web Programming (Java, Scala, Clojure, and JRuby Edition)"
+= Companion software examples for the book "Practical Semantic Web Programming (Java, Scala, Clojure, and JRuby Edition)"
This book is currently (March 2010) a work in progress and will be released around June 2010 as a print book (Lulu.com), a paid for PDF file (Lulu.com), and a free (identical) PDF file.
@@ -86,10 +86,7 @@ private static String blankNodeURI(String name_type) {
return "_:dr" + name_type + blank_node_count++;
}
static long blank_node_count = 1;
- private static String n3_to_nt(String namespace_uri) {
- int index = namespace_uri.indexOf(":");
- return "<http://localhost:2020/vocab/resource/" + namespace_uri.substring(index+1) + ">";
- }
+
// for testing only:
public static void main(String[] args) throws Exception {
List<String> people = new ArrayList<String>();
@@ -5,7 +5,6 @@
* http://markwatson.com/commerciallicense.txt
*/
-import com.freebase.api.Freebase;
import com.knowledgebooks.info_spiders.OpenCalaisClient;
import com.knowledgebooks.info_spiders.WebSpider;
import com.knowledgebooks.nlp.ExtractNames;
@@ -86,8 +85,8 @@ private void process_data_source(String uri, String text, Map<String, Set<String
for (String key : results.keySet()) {
System.out.println(" " + key + ": " + results.get(key));
for (Object val : results.get(key)) {
- String property = "<http://knowledgebooks.com/rdf/" + key + ">";
if (("" + val).length() > 0) {
+ String property = "<http://knowledgebooks.com/rdf/" + key + ">";
out.println("<" + uri + "> <http://knowledgebooks.com/rdf/" + key + "> \"" + val + "\" .");
HashSet<String> hs = (HashSet<String>) for_shared_properties.get(property);
if (hs == null) hs = new HashSet<String>();
@@ -129,7 +128,7 @@ private void process_interpage_shared_properties() throws Exception {
float url_similarity = score_mapset(shared_properties_for_all_sources.get(url_1), shared_properties_for_all_sources.get(url_2));
if (url_similarity > 12f) {
out.println("<" + url_1 + "> <http://knowledgebooks.com/rdf/high_similarity> <" + url_2 + "> .");
- } else if (url_similarity > 5f) {
+ } else if (url_similarity > 8f) {
out.println("<" + url_1 + "> <http://knowledgebooks.com/rdf/medium_similarity> <" + url_2 + "> .");
} else if (url_similarity > 5f) {
out.println("<" + url_1 + "> <http://knowledgebooks.com/rdf/low_similarity> <" + url_2 + "> .");
@@ -147,14 +146,14 @@ private float score_mapset(Map<String, Set<String>> set_1, Map<String, Set<Strin
Set<String> s1 = set_1.get(property_1);
Set<String> s2 = set_2.get(property_1);
if (s2 != null) {
- ret += score_arraylist(s1, s2);
+ ret += score_sets(s1, s2);
}
}
System.out.println(" -------------------- score_mapset: " + " ret = " + ret);
return ret;
}
- private float score_arraylist(Set<String> l_1, Set<String> l_2) {
+ private float score_sets(Set<String> l_1, Set<String> l_2) {
float ret = 0f;
for (String s : l_1) {
if (l_2.contains(s)) ret += 1f;

0 comments on commit 94fa7ee

Please sign in to comment.