Skip to content

Commit

Permalink
Allow @context to appear anywhere within the JSON-LD document
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg McFall committed Nov 25, 2013
1 parent ece1d06 commit d767af7
Show file tree
Hide file tree
Showing 17 changed files with 126 additions and 475 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ private GlobalProperties parseProperties(File source) throws IOException {
Properties properties = new Properties();
FileReader reader = new FileReader(source);
properties.load(reader);
global.setProperties(properties);

for (Map.Entry<Object, Object> e : properties.entrySet()) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Properties;
import java.util.Set;

public class GlobalProperties extends BaseDocumentMetadata {

private Set<String> ignoredOntology = new HashSet<String>();
private Properties properties;


public GlobalProperties() {
Expand All @@ -33,6 +35,22 @@ public GlobalProperties() {
}


public Properties getProperties() {
return properties;
}






public void setProperties(Properties properties) {
this.properties = properties;
}






private void createDefaultReferences() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ private void addField(ContextProperties properties, JsonContext context, Field f
} else {

addNamespace(context, rdfType);
addType(properties, context, rdfType, true);

if (!properties.getExpandedValues().contains(propertyURI)) {
String propertyTypeURI = rdfType.getUri();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class ContextManager {

// private static final Logger logger = LoggerFactory.getLogger(ContextManager.class);

public static final String SKIP_VALIDATION = "skipValidation";
private static final String RDFTYPE = "rdfType";
private static final String RDFTYPE_REF = "rdfTypeRef";
private static final String RDF_PROPERTY = "rdfProperty";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -232,20 +235,21 @@ public String rewrite(String url) {
uploader.uploadAll(pubDir);
}

validate(contextManager);
validate(contextManager, global);

ontoManager.scan(rdfDir);
ontoManager.upload();
ontoManager.uploadJsonLdContextFiles(contextManager.listContextProperties());
ontoManager.publishToLocalRepository(contextManager.listContextProperties());
}

private void validate(ContextManager manager) {
private void validate(ContextManager manager, GlobalProperties global) {
if (repoDir == null) return;
deleteDir(repoDir);
repoDir.mkdirs();

LdProcessor processor = new LdProcessor(rdfDir, repoDir, false);
LdProcessor processor = createLdProcessor(global);
processor.getContextManager().setEnhance(true);

List<ContextProperties> list = manager.listContextProperties();
// Need to publish all the contexts first because some contexts
Expand All @@ -266,16 +270,36 @@ private void validate(ContextManager manager) {



private LdProcessor createLdProcessor(GlobalProperties global) {
LdProcessor processor = new LdProcessor(rdfDir, repoDir, false);
String list = global.getProperties().getProperty(ContextManager.SKIP_VALIDATION);
if (list != null) {
StringTokenizer tokenizer = new StringTokenizer(list, " \t\r\n");
Set<String> ignoredProperties = new HashSet<String>();
while (tokenizer.hasMoreTokens()) {
ignoredProperties.add(tokenizer.nextToken());
}
processor.getValidationService().setIgnoredProperties(ignoredProperties);
}

return processor;
}


private void publishJsonLdContext(LdProcessor processor,
ContextProperties context) {

File contextFile = context.getContextFile();
if (contextFile == null) {
return;
}
try {
String contextURI = context.getContextURI();
URL url = contextFile.toURI().toURL();
LdAsset asset = new LdAsset(contextURI, LdContentType.JSON_LD_CONTEXT, url);
asset.loadContent();
processor.publish(asset);
processor.publishEnhancedContext(contextURI);

} catch (Exception e) {
getLogger().severe("Failed to add context to repo: " + contextFile);
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit d767af7

Please sign in to comment.