Commit 9b9b744a authored by pudi9346's avatar pudi9346

Added Class WikidataSearch, fixed FileSelection Bug

parent 4ba271d1
Pipeline #2980 skipped
......@@ -26,14 +26,6 @@
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
<accessrules>
<accessrule kind="accessible" pattern="javafx/**"/>
</accessrules>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<accessrules>
<accessrule kind="accessible" pattern="javafx/**"/>
</accessrules>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
......@@ -7,7 +7,7 @@ org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=ignore
org.eclipse.jdt.core.compiler.problem.enumIdentifier=ignore
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.8
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -72,7 +72,7 @@
</dependencies>
<build>
<plugins>
<plugin>
<plugin>
<!-- Used to set JRE version; will be used by IDEs like Eclipse as the
target JRE (default is 1.5) -->
<groupId>org.apache.maven.plugins</groupId>
......@@ -83,6 +83,7 @@
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>com.zenjava</groupId>
<artifactId>javafx-maven-plugin</artifactId>
......@@ -93,4 +94,13 @@
</plugin>
</plugins>
</build>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
<version>1.4.01</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
package uebung7.fin.gui;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.jena.query.QueryExecution;
import org.apache.jena.query.QueryExecutionFactory;
import org.apache.jena.query.QueryFactory;
import org.apache.jena.query.ResultSet;
import org.apache.jena.rdf.model.Model;
import com.google.gson.Gson;
import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
......@@ -32,6 +45,7 @@ import javafx.stage.Stage;
import uebung7.fin.medReader.AlphaID;
import uebung7.fin.medReader.DBSearch;
import uebung7.fin.medReader.MedReportSplitter;
import uebung7.fin.medReader.WikidataSearch;
public class Uebung7GUI1 extends Application {
......@@ -60,11 +74,20 @@ public class Uebung7GUI1 extends Application {
private static VBox leftVBox = null;
static TreeItem<String> tmpTreeItem = new TreeItem<String>();
static TreeItem<String> tmp_prop = new TreeItem<String>();
public static void main(String[] args) {
DBSearch.initDB(); // Initialize Hibernate
launch(args);
System.out.println("DBG: startGUI.java: running");
public static void main(String[] args) {
// DEBUG: Start new Wikidata Serach for Diag "G43.9"
WikidataSearch test = new WikidataSearch("G43.9");
System.out.println("DBG: Uebung7GUI1.java - Result as Json: " + test.getResult());
test.printResult();
//DBG - END
DBSearch.initDB(); // Initialize Hibernate
launch(args);
//System.out.println("DBG: startGUI.java: running");*/
System.exit(0);
}
@Override
......@@ -119,6 +142,7 @@ public class Uebung7GUI1 extends Application {
try {
// Arztbrief ans Backend übergeben, wenn Auswahl getroffen wurde
// String arztbrief = Ausgewählter Pfad
System.out.println("BDG Uebung7"+ arztBriefName);
MedReportSplitter reportSplit = new MedReportSplitter(arztBriefName);
// For FINAL VER
......
......@@ -38,14 +38,8 @@ public class MedReportSplitter {
*/
}
private void readMedLetter(String arztBriefAsStr) {
String arztBriefAsString = null;
try {
arztBriefAsString = new String(Files.readAllBytes(Paths.get("Arztbrief1.txt")));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
private void readMedLetter(String arztBriefAsString) {
// Identifizieren der Strukturwörter (Diagnose, Anamnese,...) der
// Briefe. Annahme ist, dass diese eindeutig durch Wörter mit
......
package uebung7.fin.medReader;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.jena.query.QueryExecution;
import org.apache.jena.query.QueryExecutionFactory;
import org.apache.jena.query.QueryFactory;
import org.apache.jena.rdf.model.Model;
import com.google.gson.Gson;
public class WikidataSearch {
private static String baseQuery = "PREFIX wikibase: <http://wikiba.se/ontology#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX p: <http://www.wikidata.org/prop/> PREFIX wdp: <http://www.wikidata.org/prop/direct/> PREFIX bd: <http://www.bigdata.com/rdf#> PREFIX wd: <http://www.wikidata.org/entity/> PREFIX wdt: <http://www.wikidata.org/prop/direct/> ";
private String result;
public WikidataSearch(String icdCode){
StringBuilder qur = new StringBuilder();
qur.append(baseQuery);
// build Sparql-Query from ICD-Code
qur.append("construct { ?item ?prop ?valueLabel; rdfs:Label ?itemLabel; ?prop ?pLabel} WHERE { ?item wdt:P494 \"" +icdCode +"\". ?item ?prop ?valueLabel. ?p wikibase:directClaim ?prop. SERVICE wikibase:label { bd:serviceParam wikibase:language \"en\" }}");
// Neue Query Execution: Query-Objekt erzeugen und an wikidata-sparql
// endpoint übermitteln
QueryExecution qe = QueryExecutionFactory.sparqlService("https://query.wikidata.org/sparql", QueryFactory.create(qur.toString()));
// Create Json with Results
ByteArrayOutputStream os = new ByteArrayOutputStream();
Model m = qe.execConstruct();
m.write(new PrintWriter(os), "RDFJSON" );
// Check if search returned any results
if (!os.toString().equals("{ }") ){
result = os.toString();}
// ifSearch returned no results, set results = null
else result = null;
// close bufferedByteStream
try {
os.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public String getResult(){
return result;
}
public void printResult(){
Map<String, Object> rt = new Gson().fromJson(result, Map.class);
for(Entry<String, Object> obj:rt.entrySet()){
System.out.println("\nDBG - WikiDataSearch.java:\nDBG: ItemURI:" + obj.getKey());
// Map with all Properties of an Item
Map<String, Object> diag = (Map)rt.get(obj.getKey());
// Look for the Property containing the rdf-Label of the item, print & remove it
for(Map<String, Object> nam:((ArrayList<Map>) diag.get("http://www.w3.org/2000/01/rdf-schema#Label"))){
System.out.println("DBG: ItemLabel: "+ nam.get("value"));
};
diag.remove("http://www.w3.org/2000/01/rdf-schema#Label");
// conquer each Property
for(Entry<String, Object> in:diag.entrySet()){
// ArrayList containing the Values of a Property
ArrayList<Map> val = (ArrayList)diag.get(in.getKey());
// Print URI of Property
System.out.println("\n DBG: PropertyURI:" + in.getKey());
// List all Values of a Property - The name of a property is the only entry with a size of 3
for(Map<String, Object> singleVal:val){
ArrayList<String> test = new ArrayList();
// If it's the property's name -> Print name
if(singleVal.size() == 3){
System.out.println(" DBG: PropertyLabel:" + singleVal.get("value"));
// If it's not the name, it has to be a value
} else{
System.out.println(" DBG: ValueType " + singleVal.get("type")+ " Value: " + singleVal.get("value"));
}
}
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment