-
Notifications
You must be signed in to change notification settings - Fork 5
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 #426 from hbz/persistToscienceDatastreamByMaster
Persist toscience datastream by master
- Loading branch information
Showing
9 changed files
with
309 additions
and
10 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
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
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
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,85 @@ | ||
package helper; | ||
|
||
import actions.Enrich; | ||
import actions.Modify; | ||
import actions.Read; | ||
import archive.fedora.RdfUtils; | ||
import controllers.MyController; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.InputStream; | ||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
import models.Globals; | ||
import models.Node; | ||
import org.eclipse.rdf4j.rio.RDFFormat; | ||
import java.nio.charset.StandardCharsets; | ||
import de.hbz.lobid.helper.JsonConverter; | ||
import de.hbz.lobid.helper.EtikettMakerInterface; | ||
|
||
/** | ||
* | ||
* @author adoud | ||
* | ||
*/ | ||
public class RdfHelper { | ||
|
||
/** | ||
* This method converts lobid (N-triples) into a map object | ||
* | ||
* @param node ParentNode | ||
* @param format N-Triples | ||
* @param content Lobid | ||
* @return Map Object | ||
*/ | ||
public static Map<String, Object> getRdfAsMap(Node n, RDFFormat format, | ||
String content) { | ||
|
||
Map<String, Object> rdf = null; | ||
String rewriteContent = null; | ||
EtikettMakerInterface profile = Globals.profile; | ||
JsonConverter jsonConverter = new JsonConverter(profile); | ||
|
||
if (content == null) { | ||
play.Logger.debug("Lobid (RDF) content is null"); | ||
return null; | ||
} | ||
|
||
try { | ||
|
||
if (content.contains(archive.fedora.Vocabulary.REL_MAB_527)) { | ||
String lobidUri = RdfUtils.findRdfObjects(n.getPid(), | ||
archive.fedora.Vocabulary.REL_MAB_527, content, RDFFormat.NTRIPLES) | ||
.get(0); | ||
String alephid = | ||
lobidUri.replaceFirst("http://lobid.org/resource[s]*/", ""); | ||
alephid = alephid.replaceAll("#.*", ""); | ||
content = Modify.getLobid2DataAsNtripleString(n, alephid); | ||
// updateMetadata2(node, content); | ||
rewriteContent = new Modify().rewriteContent(content, n.getPid()); | ||
play.Logger.debug("rewriteContent=" + rewriteContent); | ||
|
||
} else { | ||
rewriteContent = new Modify().rewriteContent(content, n.getPid()); | ||
play.Logger.debug("rewriteContent=" + rewriteContent); | ||
} | ||
|
||
InputStream stream = new ByteArrayInputStream( | ||
rewriteContent.getBytes(StandardCharsets.UTF_8)); | ||
|
||
rdf = jsonConverter.convert(n.getPid(), stream, format, | ||
profile.getContext().get("@context")); | ||
|
||
play.Logger.debug("getRdfAsMap(),rdf=" + rdf.toString()); | ||
|
||
rdf.remove("@context"); | ||
|
||
play.Logger.debug("rdf without key @Context=" + rdf.toString()); | ||
|
||
} catch (Exception e) { | ||
play.Logger.error("Lobid(RDF) Content could not be convert to Map", e); | ||
} | ||
return rdf; | ||
} | ||
|
||
} |
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,86 @@ | ||
package helper; | ||
|
||
import org.json.JSONObject; | ||
import java.util.List; | ||
import java.util.Iterator; | ||
import org.json.JSONArray; | ||
import helper.MyEtikettMaker; | ||
import java.util.stream.Collectors; | ||
import org.json.JSONException; | ||
import play.Play; | ||
|
||
/** | ||
* | ||
* @author adoud | ||
* | ||
*/ | ||
|
||
public class ToscienceHelper { | ||
|
||
/** | ||
* This method gets all unresolved PrefLabels and resolves them using the | ||
* MyEtikettMaker | ||
* | ||
* @param allJsonObjects | ||
* @return JSONObject with resolved prefLabels | ||
*/ | ||
public static JSONObject getPrefLabelsResolved(JSONObject allJsonObjects) { | ||
|
||
Object oldPrefLabel = null; | ||
JSONObject jsObject = null; | ||
|
||
Iterator<String> keys = allJsonObjects.keys(); | ||
|
||
try { | ||
while (keys.hasNext()) { | ||
String key = keys.next(); | ||
Object value = allJsonObjects.get(key); | ||
play.Logger.debug(" key=" + key + " ,value=" + value.toString() | ||
+ " ,artOfObject=" + value.getClass().getName()); | ||
if (value.toString().contains("prefLabel")) { | ||
play.Logger.debug("value contains prefLabel"); | ||
if (value instanceof JSONObject) { | ||
play.Logger.debug("value instanceof JSONObject"); | ||
jsObject = allJsonObjects.getJSONObject(key); | ||
play.Logger.debug("jsObject=" + jsObject.toString()); | ||
oldPrefLabel = jsObject.get("prefLabel"); | ||
if (oldPrefLabel.toString().contains("http") | ||
&& !oldPrefLabel.toString().contains("www.openstreetmap.org")) { | ||
play.Logger.debug("oldPrefLabel=" + oldPrefLabel.toString()); | ||
String newPrefLabel = | ||
MyEtikettMaker.getLabelFromEtikettWs(oldPrefLabel.toString()); | ||
play.Logger.debug("newPrefLabel=" + newPrefLabel); | ||
jsObject.put("prefLabel", newPrefLabel); | ||
} | ||
} else if (value instanceof JSONArray) { | ||
play.Logger.debug("value instanceof JSONArray"); | ||
JSONArray jsArray = allJsonObjects.getJSONArray(key); | ||
play.Logger.debug("jsArray=" + jsArray.toString()); | ||
for (int j = 0; j < jsArray.length(); j++) { | ||
jsObject = jsArray.getJSONObject(j); | ||
oldPrefLabel = jsObject.get("prefLabel"); | ||
if (oldPrefLabel.toString().contains("http") && !oldPrefLabel | ||
.toString().contains("www.openstreetmap.org")) { | ||
play.Logger.debug("oldPrefLabel=" + oldPrefLabel.toString()); | ||
String newPrefLabel = MyEtikettMaker | ||
.getLabelFromEtikettWs(oldPrefLabel.toString()); | ||
play.Logger.debug("newPrefLabel=" + newPrefLabel); | ||
jsObject.put("prefLabel", newPrefLabel); | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
} catch (JSONException e) { | ||
// Behandlung der JSONException | ||
e.printStackTrace(); | ||
} | ||
|
||
return allJsonObjects; | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.