-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #106 from mgns/feature/newCli
Code cleanup, dependencies bumped, and a new CLI
- Loading branch information
Showing
371 changed files
with
21,072 additions
and
19,254 deletions.
There are no files selected for viewing
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
182 changes: 93 additions & 89 deletions
182
archive/ISWC_2013_evaluation_track/generate_tests/DisjointExtract.java
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,126 +1,130 @@ | ||
package transform; | ||
|
||
import org.apache.commons.io.FileUtils; | ||
import org.apache.jena.ontology.OntClass; | ||
import org.apache.jena.ontology.OntModel; | ||
import org.apache.jena.util.FileManager; | ||
import org.apache.jena.util.iterator.ExtendedIterator; | ||
import org.w3c.dom.Document; | ||
import org.xml.sax.SAXException; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.HashSet; | ||
import java.util.Iterator; | ||
import java.util.Set; | ||
import javax.xml.parsers.DocumentBuilder; | ||
import javax.xml.parsers.DocumentBuilderFactory; | ||
import javax.xml.parsers.ParserConfigurationException; | ||
import javax.xml.xpath.XPath; | ||
import javax.xml.xpath.XPathConstants; | ||
import javax.xml.xpath.XPathExpressionException; | ||
import javax.xml.xpath.XPathFactory; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.HashSet; | ||
import java.util.Iterator; | ||
import java.util.Set; | ||
import org.apache.commons.io.FileUtils; | ||
import org.apache.jena.ontology.OntClass; | ||
import org.apache.jena.ontology.OntModel; | ||
import org.apache.jena.util.FileManager; | ||
import org.apache.jena.util.iterator.ExtendedIterator; | ||
import org.w3c.dom.Document; | ||
import org.xml.sax.SAXException; | ||
|
||
public class DisjointExtract { | ||
|
||
public static String dbpediaOwl = "http://mappings.dbpedia.org/server/ontology/dbpedia.owl" ; | ||
public static File file = new File("disjoint_classes.nt"); | ||
|
||
public static void main (String args[]) throws ParserConfigurationException, SAXException, IOException, XPathExpressionException { | ||
|
||
// get classes from dbpedia ontology | ||
OntModel onto = ModelFactory.createOntologyModel(); | ||
InputStream in = FileManager.get().open( dbpediaOwl ); | ||
public static String dbpediaOwl = "http://mappings.dbpedia.org/server/ontology/dbpedia.owl"; | ||
public static File file = new File("disjoint_classes.nt"); | ||
|
||
public static void main(String args[]) | ||
throws ParserConfigurationException, SAXException, IOException, XPathExpressionException { | ||
|
||
// get classes from dbpedia ontology | ||
OntModel onto = ModelFactory.createOntologyModel(); | ||
InputStream in = FileManager.get().open(dbpediaOwl); | ||
if (in == null) { | ||
throw new IllegalArgumentException( | ||
"File: " + dbpediaOwl + " not found"); | ||
throw new IllegalArgumentException( | ||
"File: " + dbpediaOwl + " not found"); | ||
} | ||
onto.read(in, null); | ||
|
||
StringBuilder triples = new StringBuilder(); | ||
Set<String> subjects = new HashSet(); | ||
Set<String> objects = new HashSet(); | ||
Set<String> tripleSet = new HashSet(); | ||
Set<String> subjects = new HashSet(); | ||
Set<String> objects = new HashSet(); | ||
Set<String> tripleSet = new HashSet(); | ||
|
||
ExtendedIterator classes = onto.listClasses(); | ||
while (classes.hasNext()) { | ||
|
||
OntClass aClass = (OntClass) classes.next(); | ||
String label = aClass.getLocalName().toString(); | ||
|
||
// get value from xml and export from mappings api | ||
String xmlFile = "http://mappings.dbpedia.org/index.php/Special:Export/OntologyClass:"+label; | ||
String text = xpath(xmlFile,"mediawiki/page/revision/text"); | ||
|
||
// get value from xml and export from mappings api | ||
String xmlFile = | ||
"http://mappings.dbpedia.org/index.php/Special:Export/OntologyClass:" + label; | ||
String text = xpath(xmlFile, "mediawiki/page/revision/text"); | ||
// only some are worth processing | ||
if (text.contains("disjoint")) { | ||
|
||
String [] lines = text.split("\n"); | ||
for (String line : lines) { | ||
if (line.contains("owl:disjointWith")){ | ||
|
||
String disjoint = line.substring(line.lastIndexOf("=")+1,line.length()).trim(); | ||
String object = "http://dbpedia.org/ontology/" + disjoint; | ||
subjects.add(aClass.getURI().toString()); | ||
objects.add(object.toString()); | ||
// get all sub-classes for found disjoint subjects | ||
if (aClass.hasSubClass()){ | ||
|
||
ExtendedIterator subclasses = aClass.listSubClasses(); | ||
while (subclasses.hasNext()) { | ||
OntClass sClass = (OntClass) subclasses.next(); | ||
subjects.add(sClass.getURI()); | ||
} | ||
} | ||
// get all sub-classes for found disjoint objects | ||
OntClass subjectClass = onto.getOntClass(object); | ||
if (subjectClass != null && subjectClass.hasSubClass()){ | ||
ExtendedIterator sub2classes = subjectClass.listSubClasses(); | ||
while (sub2classes.hasNext()) { | ||
OntClass sClass = (OntClass) sub2classes.next(); | ||
objects.add(sClass.getURI()); | ||
} | ||
} | ||
} | ||
// finally write all triples | ||
if (!subjects.isEmpty()&& !objects.isEmpty()) { | ||
Iterator itSubj = subjects.iterator(); | ||
while (itSubj.hasNext()) { | ||
String strSubj = (String) itSubj.next(); | ||
Iterator itObj = objects.iterator(); | ||
while (itObj.hasNext()) { | ||
String strObj = (String) itObj.next(); | ||
tripleSet.add("<"+strSubj +">"+" <http://www.w3.org/2002/07/owl#disjointWith> "+"<"+strObj+ "> ."); | ||
} | ||
} | ||
// cleanup sets for next class | ||
objects.clear(); | ||
subjects.clear(); | ||
String[] lines = text.split("\n"); | ||
for (String line : lines) { | ||
if (line.contains("owl:disjointWith")) { | ||
|
||
String disjoint = line.substring(line.lastIndexOf("=") + 1, line.length()).trim(); | ||
String object = "http://dbpedia.org/ontology/" + disjoint; | ||
subjects.add(aClass.getURI().toString()); | ||
objects.add(object.toString()); | ||
// get all sub-classes for found disjoint subjects | ||
if (aClass.hasSubClass()) { | ||
|
||
ExtendedIterator subclasses = aClass.listSubClasses(); | ||
while (subclasses.hasNext()) { | ||
OntClass sClass = (OntClass) subclasses.next(); | ||
subjects.add(sClass.getURI()); | ||
} | ||
} | ||
// get all sub-classes for found disjoint objects | ||
OntClass subjectClass = onto.getOntClass(object); | ||
if (subjectClass != null && subjectClass.hasSubClass()) { | ||
ExtendedIterator sub2classes = subjectClass.listSubClasses(); | ||
while (sub2classes.hasNext()) { | ||
OntClass sClass = (OntClass) sub2classes.next(); | ||
objects.add(sClass.getURI()); | ||
} | ||
} | ||
} | ||
} | ||
// finally write all triples | ||
if (!subjects.isEmpty() && !objects.isEmpty()) { | ||
Iterator itSubj = subjects.iterator(); | ||
while (itSubj.hasNext()) { | ||
String strSubj = (String) itSubj.next(); | ||
Iterator itObj = objects.iterator(); | ||
while (itObj.hasNext()) { | ||
String strObj = (String) itObj.next(); | ||
tripleSet.add( | ||
"<" + strSubj + ">" + " <http://www.w3.org/2002/07/owl#disjointWith> " + "<" | ||
+ strObj + "> ."); | ||
} | ||
} | ||
// cleanup sets for next class | ||
objects.clear(); | ||
subjects.clear(); | ||
} | ||
} | ||
} | ||
} | ||
// finally write triples to file | ||
Iterator itTriple = tripleSet.iterator(); | ||
while (itTriple.hasNext()) { | ||
String strTriple = (String) itTriple.next(); | ||
triples.append(strTriple +"\n"); | ||
} | ||
FileUtils.writeStringToFile(file, triples.toString(), true); | ||
Iterator itTriple = tripleSet.iterator(); | ||
while (itTriple.hasNext()) { | ||
String strTriple = (String) itTriple.next(); | ||
triples.append(strTriple + "\n"); | ||
} | ||
FileUtils.writeStringToFile(file, triples.toString(), true); | ||
} | ||
|
||
// get value from xml file | ||
public static String xpath (String xmlFile, String path) throws ParserConfigurationException, SAXException, IOException, XPathExpressionException { | ||
|
||
public static String xpath(String xmlFile, String path) | ||
throws ParserConfigurationException, SAXException, IOException, XPathExpressionException { | ||
|
||
InputStream is = FileManager.get().open(xmlFile); | ||
DocumentBuilderFactory xmlFactory = DocumentBuilderFactory.newInstance(); | ||
DocumentBuilder docBuilder = xmlFactory.newDocumentBuilder(); | ||
Document xmlDoc = docBuilder.parse(is); | ||
XPathFactory xpathFact = XPathFactory.newInstance(); | ||
XPath xpath = xpathFact.newXPath(); | ||
String text = (String) xpath.evaluate(path , xmlDoc, XPathConstants.STRING); | ||
return text; | ||
} | ||
|
||
String text = (String) xpath.evaluate(path, xmlDoc, XPathConstants.STRING); | ||
|
||
return text; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/bin/bash | ||
|
||
# | ||
# example call for dump-based testing (You can use either a URI or a local file name): | ||
# bin/rdfunit -d https://raw.github.com/AKSW/n3-collection/master/News-100.ttl -s nif | ||
# | ||
# example call for endpoint-based testing (dbpedia): | ||
# bin/rdfunit -d http://dbpedia.org -e http://dbpedia.org/sparql -g http://dbpedia.org -p dbo -s "owl,dbo,foaf,dcterms,dc,skos,geo,prov" | ||
# | ||
|
||
MAIN_CLS="org.aksw.rdfunit.validate.cli.CLI" | ||
|
||
# TODO use the jar for faster execution | ||
#if [ -s bin/rdfunit.jar ] | ||
#then | ||
# mvn assembly:single -DdescriptorId=jar-with-dependencies | ||
# cp /tmp/docu.html "$doc"".html" | ||
#fi | ||
|
||
if [ ! -d "rdfunit-validate/target" ]; then | ||
echo "First run, compiling code..." | ||
mvn -pl rdfunit-validate -am clean install \ | ||
-Dmaven.test.skip=true \ | ||
-Dmaven.javadoc.skip=true \ | ||
-Dgpg.skip=true \ | ||
-Dsource.skip=true | ||
echo "Compiling finished..." | ||
fi | ||
|
||
mvn -pl rdfunit-validate exec:java -q -Dexec.mainClass="$MAIN_CLS" -Dexec.args="generate $*" |
Oops, something went wrong.