From: <sk...@us...> - 2008-10-26 19:28:52
|
Revision: 1426 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1426&view=rev Author: sknappe Date: 2008-10-26 19:28:48 +0000 (Sun, 26 Oct 2008) Log Message: ----------- new Ontology Script Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/scripts/CalculatePageRank.java Modified: trunk/src/dl-learner/org/dllearner/scripts/CalculatePageRank.java =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/CalculatePageRank.java 2008-10-24 13:38:01 UTC (rev 1425) +++ trunk/src/dl-learner/org/dllearner/scripts/CalculatePageRank.java 2008-10-26 19:28:48 UTC (rev 1426) @@ -49,6 +49,8 @@ private final String wikilinks = datasetDir + "pagelinks_en.nt"; private final String labels = datasetDir + "articles_label_en.nt"; private final String categories = datasetDir + "yago_en.nt"; + private final String categoriesNewOntology = datasetDir + "dbpedia-ontology-schema.nt"; + private final String categoriesNewOntology2 = datasetDir + "dbpedia-ontology-types.nt"; private static String dbServer; private static String dbName; @@ -181,8 +183,6 @@ stmt = con.createStatement(); - stmt.executeUpdate("ALTER TABLE rank DROP COLUMN category"); - BufferedReader in = new BufferedReader(new FileReader(categories)); String line; @@ -237,6 +237,96 @@ } } + private void calculateCategoriesNewOntology() + { + try{ + Statement stmt; + + Class.forName("com.mysql.jdbc.Driver"); + + String url = + "jdbc:mysql://localhost:3306/navigator_db"; + + Connection con = DriverManager.getConnection( + url,"navigator", "dbpedia"); + + stmt = con.createStatement(); + + BufferedReader in = new BufferedReader(new FileReader(categoriesNewOntology)); + + String line; + String[] split; + String name; + String label; + String pred; + int i=0; + boolean isClassLabel; + String className; + while ((line=in.readLine())!=null) + { + split=line.split(">"); + name=split[0].substring(1); + className=name.substring(name.lastIndexOf("/")+1,name.lastIndexOf("/")+2); + if (className.toLowerCase().equals(className)) + isClassLabel=false; + else + isClassLabel=true; + pred=split[1].substring(2); + if (pred.equals("http://www.w3.org/2000/01/rdf-schema#label")) + label=split[2].substring(split[2].indexOf("\"")+1, split[2].lastIndexOf("\"")); + else + label=split[2].substring(2); + if (pred.equals("http://www.w3.org/2000/01/rdf-schema#label")&&isClassLabel){ + try{ + stmt.executeUpdate("INSERT INTO categories (category,label) VALUES (\""+name+"\",\""+label+"\")"); + }catch(Exception e) + {} + } + else{ + if (pred.equals("http://www.w3.org/2000/01/rdf-schema#subClassOf")){ + try{ + stmt.executeUpdate("INSERT INTO classhierarchy (father,child) VALUES ('"+label+"','"+name+"')"); + }catch(Exception e) + {} + } + } + if (i%100000==0) System.out.println(i); + i++; + } + + in.close(); + + in = new BufferedReader(new FileReader(categoriesNewOntology2)); + + i=0; + while ((line=in.readLine())!=null) + { + split=line.split(">"); + name=split[0].substring(1); + label=split[2].substring(2); + try{ + stmt.executeUpdate("INSERT INTO articlecategories (name,category) VALUES ('"+name+"','"+label+"')"); + }catch(Exception e) + {} + if (i%100000==0) System.out.println(i); + i++; + } + + in.close(); + + con.close(); + } catch (FileNotFoundException e) + { + System.out.println("File not found"); + } catch (IOException e) + { + System.out.println("IOException"); + } catch (Exception e) + { + e.printStackTrace(); + } + } + private void copyNumbers() { try{ @@ -274,7 +364,8 @@ CalculatePageRank cal=new CalculatePageRank(); cal.calculateLinks(); cal.addLabels(); - cal.calculateCategories(); + //cal.calculateCategories(); + cal.calculateCategoriesNewOntology(); cal.copyNumbers(); } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |