本文整理汇总了Java中org.apache.jena.atlas.json.JSON.parse方法的典型用法代码示例。如果您正苦于以下问题:Java JSON.parse方法的具体用法?Java JSON.parse怎么用?Java JSON.parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.jena.atlas.json.JSON
的用法示例。
在下文中一共展示了JSON.parse方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getConcept
import org.apache.jena.atlas.json.JSON; //导入方法依赖的package包/类
/**
* Return the concept with the supplied URI with pref label, uri and type fields populated
* @param conceptUri - the concept to be returned
* @return - the requested concept
* @throws OEClientException - an error has occurred contacting the server
*/
public Concept getConcept(String conceptUri) throws OEClientException {
logger.info("getConcept entry: {}", conceptUri);
Map<String, String> queryParameters = new HashMap<String, String>();
queryParameters.put("properties", basicProperties);
queryParameters.put("path", getPathParameter(conceptUri));
Invocation.Builder invocationBuilder = getInvocationBuilder(getApiURL(), queryParameters);
Date startDate = new Date();
logger.info("getConcept making call : {}", startDate.getTime());
Response response = invocationBuilder.get();
logger.info("getConcept call complete: {}", startDate.getTime());
logger.info("getConceptDetails - status: {}", response.getStatus());
if (response.getStatus() == 200) {
String stringResponse = response.readEntity(String.class);
if (logger.isDebugEnabled()) logger.debug("getConceptDetails: jsonResponse {}", stringResponse);
JsonObject jsonResponse = JSON.parse(stringResponse);
return new Concept(this, jsonResponse.get("@graph").getAsArray().get(0).getAsObject());
} else {
throw new OEClientException(String.format("Error(%d) %s from server", response.getStatus(), response.getStatusInfo().toString()));
}
}
示例2: getConceptByIdentifier
import org.apache.jena.atlas.json.JSON; //导入方法依赖的package包/类
/**
* Return the concept with the supplied identifier
* @param identifier - the unique identifier for the concept (not the URI)
* @return - the requested concept
* @throws OEClientException - an error has occurred contacting the server
*/
public Concept getConceptByIdentifier(Identifier identifier) throws OEClientException {
logger.info("getConceptByIdentifier entry: {}", identifier);
String url = getModelURL() + "/skos:Concept/meta:transitiveInstance";
Map<String, String> queryParameters = new HashMap<String, String>();
queryParameters.put("properties", basicProperties);
queryParameters.put("filters", String.format("subject(exists %s \"%s\")", getWrappedUri(identifier.getUri()), identifier.getValue()));
Invocation.Builder invocationBuilder = getInvocationBuilder(url, queryParameters);
Date startDate = new Date();
logger.info("getConceptByIdentifier making call : {}", startDate.getTime());
Response response = invocationBuilder.get();
logger.info("getConceptByIdentifier call complete: {}", startDate.getTime());
logger.info("getConceptByIdentifier - status: {}", response.getStatus());
if (response.getStatus() == 200) {
String stringResponse = response.readEntity(String.class);
if (logger.isDebugEnabled()) logger.debug("getConceptByIdentifier: jsonResponse {}", stringResponse);
JsonObject jsonResponse = JSON.parse(stringResponse);
return new Concept(this, jsonResponse.get("@graph").getAsArray().get(0).getAsObject());
} else {
throw new OEClientException(String.format("Error(%d) %s from server", response.getStatus(), response.getStatusInfo().toString()));
}
}
示例3: populateRelatedConceptUris
import org.apache.jena.atlas.json.JSON; //导入方法依赖的package包/类
public void populateRelatedConceptUris(String relationshipUri, Concept concept) throws OEClientException {
logger.info("populateNarrowerConceptURIs entry: {}", concept.getUri());
Map<String, String> queryParameters = new HashMap<String, String>();
queryParameters.put("properties", getWrappedUri(relationshipUri));
Invocation.Builder invocationBuilder = getInvocationBuilder(getResourceURL(concept.getUri()), queryParameters);
Date startDate = new Date();
logger.info("populateNarrowerConceptURIs making call : {}", startDate.getTime());
Response response = invocationBuilder.get();
logger.info("populateNarrowerConceptURIs call complete: {}", startDate.getTime());
logger.info("populateNarrowerConceptURIs - status: {}", response.getStatus());
if (response.getStatus() == 200) {
String stringResponse = response.readEntity(String.class);
if (logger.isDebugEnabled()) logger.debug("populateNarrowerConceptURIs: jsonResponse {}", stringResponse);
JsonObject jsonResponse = JSON.parse(stringResponse);
concept.populateRelatedConceptUris(relationshipUri, jsonResponse.get("@graph").getAsArray().get(0).getAsObject());
} else {
throw new OEClientException(String.format("Error(%d) %s from server", response.getStatus(), response.getStatusInfo().toString()));
}
}
示例4: populateMetadata
import org.apache.jena.atlas.json.JSON; //导入方法依赖的package包/类
public void populateMetadata(String metadataUri, Concept concept) throws OEClientException {
logger.info("populateMetadata entry: {}", concept.getUri());
Map<String, String> queryParameters = new HashMap<String, String>();
queryParameters.put("properties", getWrappedUri(metadataUri));
Invocation.Builder invocationBuilder = getInvocationBuilder(getResourceURL(concept.getUri()), queryParameters);
Date startDate = new Date();
logger.info("populateMetadata making call : {}", startDate.getTime());
Response response = invocationBuilder.get();
logger.info("populateMetadata call complete: {}", startDate.getTime());
logger.info("populateMetadata - status: {}", response.getStatus());
if (response.getStatus() == 200) {
String stringResponse = response.readEntity(String.class);
if (logger.isDebugEnabled()) logger.debug("populateNarrowerConceptURIs: jsonResponse {}", stringResponse);
JsonObject jsonResponse = JSON.parse(stringResponse);
concept.populateMetadata(metadataUri, jsonResponse.get("@graph").getAsArray().get(0).getAsObject());
} else {
throw new OEClientException(String.format("Error(%d) %s from server", response.getStatus(), response.getStatusInfo().toString()));
}
}
示例5: run
import org.apache.jena.atlas.json.JSON; //导入方法依赖的package包/类
@Override
public void run(Model results) throws Exception {
Resource testCase = getResource();
String queryString = JenaUtil.getStringProperty(testCase, SH.select);
Model model = testCase.getModel();
JsonObject expectedJSON = JSON.parse(JenaUtil.getStringProperty(testCase, DASH.expectedResult));
for(TestCaseContextFactory contextFactory : contextFactories) {
TestCaseContext context = contextFactory.createContext();
context.setUpTestContext();
try {
String actual = createResultSetJSON(queryString, model);
JsonObject actualJSON = JSON.parse(actual);
if(!actualJSON.equals(expectedJSON)) {
createFailure(results, "Mismatching result set. Actual: " + actual, context);
return;
}
}
finally {
context.tearDownTestContext();
}
}
createResult(results, DASH.SuccessTestCaseResult);
}
示例6: getAllModels
import org.apache.jena.atlas.json.JSON; //导入方法依赖的package包/类
public Collection<Model> getAllModels() throws OEClientException {
logger.info("getAllModels entry");
String url = getApiURL() + "/sys/sys:Model/rdf:instance";
logger.info("getAllModels URL: {}", url);
Map<String, String> queryParameters = new HashMap<String, String>();
queryParameters.put("properties", "meta:displayName,meta:graphUri");
Invocation.Builder invocationBuilder = getInvocationBuilder(url, queryParameters);
Date startDate = new Date();
logger.info("getAllModels making call : {}", startDate.getTime());
Response response = invocationBuilder.get();
logger.info("getAllModels call complete: {}", startDate.getTime());
logger.info("getAllModels - status: {}", response.getStatus());
if (response.getStatus() == 200) {
String stringResponse = response.readEntity(String.class);
if (logger.isInfoEnabled()) logger.info("getAllModels: jsonResponse {}", stringResponse);
JsonObject jsonResponse = JSON.parse(stringResponse);
JsonArray jsonArray = jsonResponse.get("@graph").getAsArray();
Collection<Model> models = new ArrayList<Model>();
Iterator<JsonValue> jsonValueIterator = jsonArray.iterator();
while (jsonValueIterator.hasNext()) {
JsonObject modelObject = jsonValueIterator.next().getAsObject();
models.add(new Model(modelObject));
}
return models;
} else {
throw new OEClientException(String.format("Error(%d) %s from server", response.getStatus(), response.getStatusInfo().toString()));
}
}
示例7: getRelationshipTypes
import org.apache.jena.atlas.json.JSON; //导入方法依赖的package包/类
private Collection<RelationshipType> getRelationshipTypes(String parentType) throws OEClientException {
logger.info("getRelationshipTypes entry: {}", parentType);
Map<String, String> queryParameters = new HashMap<String, String>();
queryParameters.put("properties", "rdfs:label,owl:inverseOf,rdfs:subPropertyOf,owl:inverseOf/rdfs:label,owl:inverseOf/rdfs:subPropertyOf");
Invocation.Builder invocationBuilder = getInvocationBuilder(getModelURL() + "/" + parentType +"/meta:transitiveSubProperty", queryParameters);
Date startDate = new Date();
logger.info("getRelationshipTypes making call : {}", startDate.getTime());
Response response = invocationBuilder.get();
logger.info("getRelationshipTypes call complete: {}", startDate.getTime());
logger.info("getRelationshipTypes - status: {}", response.getStatus());
if (response.getStatus() == 200) {
String stringResponse = response.readEntity(String.class);
if (logger.isInfoEnabled()) logger.info("getConceptClasses: jsonResponse {}", stringResponse);
JsonObject jsonResponse = JSON.parse(stringResponse);
JsonArray jsonArray = jsonResponse.get("@graph").getAsArray();
Collection<RelationshipType> relationshipTypes = new HashSet<RelationshipType>();
Iterator<JsonValue> jsonValueIterator = jsonArray.iterator();
while (jsonValueIterator.hasNext()) {
relationshipTypes.add(new RelationshipType(this, jsonValueIterator.next().getAsObject()));
}
return relationshipTypes;
} else {
throw new OEClientException(String.format("Error(%d) %s from server", response.getStatus(), response.getStatusInfo().toString()));
}
}
示例8: getConceptClasses
import org.apache.jena.atlas.json.JSON; //导入方法依赖的package包/类
/**
* Return all concept classes
* @return - a collection containing all concept classes
* @throws OEClientException - an error has occurred contacting the server
*/
public Collection<ConceptClass> getConceptClasses(int limit) throws OEClientException {
logger.info("getConceptClasses entry");
Map<String, String> queryParameters = new HashMap<String, String>();
queryParameters.put("properties", "rdfs:label,rdfs:subClassOf");
queryParameters.put("limit", Integer.toString(limit));
Invocation.Builder invocationBuilder = getInvocationBuilder(getModelURL() + "/skos:Concept/meta:transitiveSubClass", queryParameters);
Date startDate = new Date();
logger.info("getConceptClasses making call : {}", startDate.getTime());
Response response = invocationBuilder.get();
logger.info("getConceptClasses call complete: {}", startDate.getTime());
logger.info("getConceptClasses - status: {}", response.getStatus());
if (response.getStatus() == 200) {
String stringResponse = response.readEntity(String.class);
if (logger.isInfoEnabled()) logger.info("getConceptClasses: jsonResponse {}", stringResponse);
JsonObject jsonResponse = JSON.parse(stringResponse);
JsonArray jsonArray = jsonResponse.get("@graph").getAsArray();
Collection<ConceptClass> conceptClasses = new HashSet<ConceptClass>();
Iterator<JsonValue> jsonValueIterator = jsonArray.iterator();
while (jsonValueIterator.hasNext()) {
conceptClasses.add(new ConceptClass(this, jsonValueIterator.next().getAsObject()));
}
return conceptClasses;
} else {
throw new OEClientException(String.format("Error(%d) %s from server", response.getStatus(), response.getStatusInfo().toString()));
}
}
示例9: append
import org.apache.jena.atlas.json.JSON; //导入方法依赖的package包/类
@Override
public long append(Id dsRef, RDFPatch patch) {
checkLink();
long t1 = System.currentTimeMillis();
String str = retry(()->{
RDFChangesHTTP remote = createRDFChanges(dsRef);
// [NET] Network point
// If not re-applyable, we need a copy.
patch.apply(remote);
return remote.getResponse();
},
()->patch.repeatable(),
()->"Retry append patch.", ()->"Failed to append patch : "+dsRef);
long t2 = System.currentTimeMillis();
long elapsed_ms = (t2-t1);
if ( str != null ) {
try {
JsonObject obj = JSON.parse(str);
int version = obj.get(DeltaConst.F_VERSION).getAsNumber().value().intValue();
return version;
} catch (Exception ex) {
FmtLog.warn(this.getClass(), "[%s] Error in response body : %s", dsRef, ex.getMessage());
}
} else {
FmtLog.warn(this.getClass(), "[%s] No response body", dsRef);
}
// No response body or syntax error.
return -1;
}
示例10: getRequestStatus
import org.apache.jena.atlas.json.JSON; //导入方法依赖的package包/类
public static String getRequestStatus(String uuid) throws InterruptedException, ExecutionException{
if (computeResourceDirectory.get(uuid) != null){
if (!finishedResources.contains(uuid)){
Future<String> handler = computingResources.get(uuid);
if (handler.isDone()){
String result = handler.get();
computeResourceDirectory.remove(uuid);
computeResourceDirectory.put(uuid, result);
JsonObject jobj = JSON.parse(result);
String outcome = jobj.get("Outcome").getAsString().value();
if (outcome.contains("SUCCESS")){
successfulResources.add(uuid);
} else {
failedResources.add(uuid);
}
finishedResources.add(uuid);
}
}
return computeResourceDirectory.get(uuid);
} else {
StringBuilder sb = new StringBuilder();
sb.append("{");
sb.append("\"Agent\": \"" + BASE_URI + "\", ");
sb.append("\"RequestID\": \"" + uuid + "\", ");
sb.append("\"Error\": \"Request ID not Found\"");
sb.append("}");
return sb.toString();
}
}
示例11: getAllTasks
import org.apache.jena.atlas.json.JSON; //导入方法依赖的package包/类
/**
* getAllTasks
* @return all the tasks present for this model
* @throws OEClientException - an error has occurred contacting the server
*/
public Collection<Task> getAllTasks() throws OEClientException {
logger.info("getAllTasks entry");
String url = getModelSysURL();
logger.info("getAllTasks URL: {}", url);
Map<String, String> queryParameters = new HashMap<String, String>();
queryParameters.put("properties", "meta:hasTask/(meta:graphUri|meta:displayName)");
queryParameters.put("filters", "subject_hasTask(notExists rdf:type sem:ORTTask)");
Invocation.Builder invocationBuilder = getInvocationBuilder(url, queryParameters);
Date startDate = new Date();
logger.info("getAllTasks making call : {}", startDate.getTime());
Response response = invocationBuilder.get();
logger.info("getAllTasks call complete: {}", startDate.getTime());
logger.info("getAllTasks - status: {}", response.getStatus());
if (response.getStatus() == 200) {
String stringResponse = response.readEntity(String.class);
if (logger.isInfoEnabled()) logger.info("getAllTasks: jsonResponse {}", stringResponse);
JsonObject jsonResponse = JSON.parse(stringResponse);
JsonArray jsonArray = jsonResponse.get("@graph").getAsArray();
Collection<Task> tasks = new ArrayList<Task>();
Iterator<JsonValue> jsonValueIterator = jsonArray.iterator();
while (jsonValueIterator.hasNext()) {
JsonObject modelData = jsonValueIterator.next().getAsObject();
JsonArray taskArray = modelData.get("meta:hasTask").getAsArray();
Iterator<JsonValue> jsonTaskIterator = taskArray.iterator();
while (jsonTaskIterator.hasNext()) {
tasks.add(new Task(jsonTaskIterator.next().getAsObject()));
}
}
return tasks;
} else {
throw new OEClientException(String.format("Error(%d) %s from server", response.getStatus(), response.getStatusInfo().toString()));
}
}
示例12: getChangesSince
import org.apache.jena.atlas.json.JSON; //导入方法依赖的package包/类
public Collection<ChangeRecord> getChangesSince(Date date) throws OEClientException {
StringBuilder stringBuilder = new StringBuilder(baseURL);
if (!baseURL.endsWith("/")) stringBuilder.append("/");
stringBuilder.append("api/");
stringBuilder.append("t/");
stringBuilder.append(token);
stringBuilder.append("/tch");
stringBuilder.append(modelUri);
stringBuilder.append("/teamwork:Change/rdf:instance");
String url = stringBuilder.toString();
logger.debug("getChangesSince: '{}'", url);
Map<String, String> queryParameters = new HashMap<String, String>();
queryParameters.put("properties", "?triple/(teamwork:subject|teamwork:predicate|teamwork:object),sem:committed");
queryParameters.put("filters", String.format("subject(sem:committed >= \"%s\"^^xsd:dateTime)", date.toInstant().toString()));
queryParameters.put("sort", "sem:committed");
Invocation.Builder invocationBuilder = getInvocationBuilder(url, queryParameters);
Date startDate = new Date();
logger.info("getChangesSince making call : {}", startDate.getTime());
Response response = invocationBuilder.get();
logger.info("getChangesSince call complete: {}", startDate.getTime());
logger.info("getChangesSince - status: {}", response.getStatus());
if (response.getStatus() == 200) {
String stringResponse = response.readEntity(String.class);
if (logger.isInfoEnabled()) logger.info("getChangesSince: jsonResponse {}", stringResponse);
JsonObject jsonResponse = JSON.parse(stringResponse);
JsonArray jsonArray = jsonResponse.get("@graph").getAsArray();
Collection<ChangeRecord> changeRecords = new ArrayList<ChangeRecord>();
Iterator<JsonValue> jsonValueIterator = jsonArray.iterator();
while (jsonValueIterator.hasNext()) {
changeRecords.add(new ChangeRecord(this, jsonValueIterator.next().getAsObject()));
}
return changeRecords;
} else {
throw new OEClientException(String.format("Error(%d) %s from server", response.getStatus(), response.getStatusInfo().toString()));
}
}
示例13: append
import org.apache.jena.atlas.json.JSON; //导入方法依赖的package包/类
@Override
public long append(String dsName, RDFPatch patch) {
String idStr = Id.str(patch.getId());
// Need registration.
String s = url+dsName+"?token="+regToken.asString();
ByteArrayOutputStream out = new ByteArrayOutputStream(100*1024);
RDFPatchOps.write(out, patch);
HttpPost postRequest = new HttpPost(s);
byte[] bytes = out.toByteArray();
postRequest.setEntity(new ByteArrayEntity(bytes));
String response;
try(CloseableHttpResponse r = httpClient.execute(postRequest) ) {
StatusLine statusLine = r.getStatusLine();
response = readResponse(r);
int sc = r.getStatusLine().getStatusCode();
if ( sc <= 199 ) {}
if ( sc >= 300 ) {
if ( sc >= 300 && sc <= 399 ) {
FmtLog.info(LOG, "Send patch %s HTTP %d", idStr, sc);
throw new DeltaHttpException(sc, "HTTP Redirect");
}
if ( sc >= 400 && sc <= 499 )
throw new DeltaHttpException(sc, r.getStatusLine().getReasonPhrase());
if ( sc >= 500 )
throw new DeltaHttpException(sc, r.getStatusLine().getReasonPhrase());
}
} catch (IOException e) { throw IOX.exception(e); }
if ( response != null ) {
try {
JsonObject obj = JSON.parse(response);
int version = obj.get(DeltaConst.F_VERSION).getAsNumber().value().intValue();
return version;
} catch (Exception ex) { ex.printStackTrace(); }
}
return 0;
}
示例14: setStateFromString
import org.apache.jena.atlas.json.JSON; //导入方法依赖的package包/类
/** Set version and datasource id from a string which is JOSN */
private static void setStateFromString(DataState state, String string) {
JsonObject obj = JSON.parse(string);
setFromJsonObject(state, obj);
}