Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

…s, Freebase, and DBpedia
  • Loading branch information...
commit 94fa7ee68009d4b794c854d7ceb016a5f58905bd 1 parent 553a690
@mark-watson authored
View
5 Java_practical_semantic_web.iml
@@ -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
2  README.rdoc
@@ -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.
View
5 examples/EntityToD2RHelpers.java
@@ -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>();
View
9 examples/RdfDataGenerationApplication.java
@@ -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;
Please sign in to comment.
Something went wrong with that request. Please try again.