Java Code Examples for org.apache.jena.atlas.json.JSON#read()

The following examples show how to use org.apache.jena.atlas.json.JSON#read() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EntityJSONRDFReader.java    From JedAIToolkit with Apache License 2.0 5 votes vote down vote up
private void readModel(String inpFIle) throws IOException, NotFoundException {
    //read each ntriples
    JsonObject jsonObject = JSON.read(inpFIle);
    String key = jsonObject.keys().toArray()[0].toString();
    JsonArray jarr = jsonObject.get(key).getAsArray();

    // JSON file example:
    /*{"triples":
    [
    {Subject: "OperaHouse", Predicate: "located_in", Object: "Sydney"},
    {Subject: "Sydney", Predicate: "located_in", Object: "Australia"},
    ......
     */
    jarr.forEach((jsonValue) -> {
        final CharSequence predicate = jsonValue.getAsObject().get("Predicate").toString();
        final String pred = predicate.toString();
        if (!(attributesToExclude.contains(pred))) {
            final CharSequence subject = jsonValue.getAsObject().get("Subject").toString();
            String sub = subject.toString();
            if (!prefix.equals("")) {
                sub = sub.replace(prefix, "");
            }   final CharSequence object = jsonValue.getAsObject().get("Object").toString();
            final String obj = object.toString();
            //if already exists a profile for the subject, simply add po as <Att>-<Value>
            EntityProfile entityProfile = urlToEntity.get(sub);
            if (entityProfile == null) {
                entityProfile = new EntityProfile(sub);
                entityProfiles.add(entityProfile);
                urlToEntity.put(sub, entityProfile);
            }   if (!obj.isEmpty()) {
                entityProfile.addAttribute(pred, obj);
            }
        }
    });

}
 
Example 2
Source File: PatchStoreAnyLocal.java    From rdf-delta with Apache License 2.0 5 votes vote down vote up
private PatchStore choose(DataSourceDescription dsd, Path patchLogDir) {
    //Look in source.cfg.
    if ( ! Files.exists(patchLogDir) )
        return patchStoreDefaultNew;
    Path sourceCfgPath = patchLogDir.resolve(FileNames.DS_CONFIG);
    if ( ! Files.exists(sourceCfgPath) ) {
        // Directory, no source.cfg.
        return patchStoreDefaultNew;
    }

    try {
        //c.f. LocalServerConfig.
        JsonObject obj = JSON.read(sourceCfgPath.toString());
        DataSourceDescription dsdCfg = DataSourceDescription.fromJson(obj);
        String logTypeName = obj.get(F_LOG_TYPE).getAsString().value();
        if ( logTypeName != null ) {
            Provider provider = DPS.providerByName(logTypeName);
            if ( provider == null )
                throw new DeltaConfigException("Unknown log type: "+logTypeName);
            switch(provider) {
                case FILE :  return patchStoreFile;
                case MEM :   return patchStoreMem;
                case ROCKS : return patchStoreRocks;
                case LOCAL :
                    throw new DeltaException(dsdCfg.getName()+":"+FileNames.DS_CONFIG+" : log_type = local");
                default:
                    throw new DeltaException(dsdCfg.getName()+":"+FileNames.DS_CONFIG+" : log_type not for a local patch store");
            }
        }
        Path dbPath = patchLogDir.resolve(RocksConst.databaseFilename).toAbsolutePath();
        boolean rocks = Files.exists(dbPath);
        if ( rocks )
            return patchStoreRocks;
        return patchStoreDefaultNew;
    } catch (Exception ex) {
        throw new DeltaException("Exception while reading log configuration: "+dsd.getName(), ex);
    }
}
 
Example 3
Source File: DeltaBackupServer.java    From rdf-delta with Apache License 2.0 5 votes vote down vote up
private void parseConf(BackupConfig cfg, String cfgFile) {
    try {
        JsonObject obj = JSON.read(cfgFile);
        cfg.port = obj.get(jPort).getAsNumber().value().intValue();
        JsonArray a = obj.get(jLogs).getAsArray();
        a.forEach(elt-> {
            BackupArea area = parseLogObject(cfg, elt);
            cfg.logs.add(area);
        });
    } catch (Exception ex) {
        throw new CmdException("Failed to process configuration file: "+ex.getMessage());
    }
}
 
Example 4
Source File: DeltaServerConfig.java    From rdf-delta with Apache License 2.0 4 votes vote down vote up
public static DeltaServerConfig read(String file) {
    JsonObject obj = JSON.read(file);
    return create(obj);
}
 
Example 5
Source File: LocalServerConfig.java    From rdf-delta with Apache License 2.0 4 votes vote down vote up
/** Parse a configuration file. */
public Builder parse(String configFile) {
    // Relationship to DeltaServerConfig in command line.
    Path path = Paths.get(configFile);
    if ( ! Files.exists(path) )
        throw new DeltaConfigException("File not found: "+configFile);
    // -- version
    JsonObject obj = JSON.read(configFile);
    int version = JSONX.getInt(obj, F_VERSION, -99);
    if ( version == -99 ) {
        LOG.warn("No version number for the configuration file : assuming 'current'");
        version = DeltaConst.SYSTEM_VERSION;
    }
    if ( version != SYSTEM_VERSION )
        throw new DeltaConfigException("Version number for LocalServer must be "+DeltaConst.SYSTEM_VERSION+".");

    this.configFile = configFile;

    // -- log provider
    // Default.
    logProvider = Provider.LOCAL;
    String logTypeName = JSONX.getStrOrNull(obj, F_LOG_TYPE);
    if ( logTypeName != null ) {
        Provider provider = DPS.providerByName(logTypeName);
        if ( provider == null )
            throw new DeltaConfigException("Unknown log type: "+logTypeName);
        logProvider = provider ;
    }
    // -- store (file, rocks, any local)
    if ( isLocalProvider(logProvider) ) {
        String store = JSONX.getStrOrNull(obj, F_STORE);
        Path storeLocation = null;
        if ( store == null )
            // Default to directory where the config file is.
            storeLocation = path.getParent();
        else
            storeLocation = path.getParent().resolve(store);

        if ( storeLocation != null )
            setProperty(DeltaConst.pDeltaStore, storeLocation.toString());
    }
    // TODO -- General properties.
    return this;
}