Java Code Examples for org.apache.jena.riot.Lang#TTL

The following examples show how to use org.apache.jena.riot.Lang#TTL . 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: DatahubNIFConfig.java    From gerbil with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * We have to synchronize this method. Otherwise every experiment thread
 * would check the file and try to download the data or try to use the file
 * even the download hasn't been completed.
 */
@Override
protected synchronized Dataset loadDataset() throws Exception {
    String nifFile = GerbilConfiguration.getInstance().getString(DATAHUB_DATASET_FILE_PROPERTY_NAME) + getName();
    logger.debug("FILE {}", nifFile);
    File f = new File(nifFile);
    if (!f.exists()) {
        logger.debug("file {} does not exist. need to download", nifFile);
        String data = rt.getForObject(datasetUrl, String.class);
        Path path = Paths.get(nifFile);
        Files.createDirectories(path.getParent());
        Path file = Files.createFile(path);
        Files.write(file, data.getBytes(), StandardOpenOption.WRITE);
    }
    FileBasedNIFDataset dataset = new FileBasedNIFDataset(nifFile, getName(), Lang.TTL);
    dataset.init();
    return dataset;
}
 
Example 2
Source File: NIFDatasetLoadingTest.java    From gerbil with GNU Affero General Public License v3.0 6 votes vote down vote up
public static void main(String[] args) {
    if (args.length != 1) {
        LOGGER.error(
                "Wrong usage. Need exactly one single argument. Correct usage: 'NIFDatasetLoadingTest <path-to-nif-file>'.");
        return;
    }
    LOGGER.info("Starting loading of given test dataset \"" + args[0] + "\"...");
    FileBasedNIFDataset dataset = new FileBasedNIFDataset(args[0], "Test dataset", Lang.TTL);
    try {
        dataset.init();
    } catch (GerbilException e) {
        LOGGER.error("Got an exception while trying to load the dataset.", e);
    }
    List<Document> documents = dataset.getInstances();
    LOGGER.info("Dataset size: {} documents", documents.size());
    ObjectIntOpenHashMap<String> annotationTypes;
    for (Document document : documents) {
        annotationTypes = listAnnotationTypes(document);
        LOGGER.info("Document {} annotation types: {}", document.getDocumentURI(), annotationTypes.toString());
    }
    IOUtils.closeQuietly(dataset);
    LOGGER.info("Finished loading of given test dataset.");
}
 
Example 3
Source File: QueryOperation.java    From robot with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Convert a format name string to a language code.
 *
 * @param formatName the format name as a string
 * @return the format language code or null
 */
public static Lang getFormatLang(String formatName) {
  Lang format;
  formatName = formatName.toLowerCase();
  switch (formatName) {
    case "tsv":
      format = ResultSetLang.SPARQLResultSetTSV;
      break;
    case "ttl":
      format = Lang.TTL;
      break;
    case "jsonld":
      format = Lang.JSONLD;
      break;
    case "nt":
      format = Lang.NT;
      break;
    case "nq":
      format = Lang.NQ;
      break;
    case "csv":
      format = Lang.CSV;
      break;
    case "xml":
      format = Lang.RDFXML;
      break;
    case "sxml":
      format = ResultSetLang.SPARQLResultSetXML;
      break;
    default:
      format = null;
  }
  return format;
}
 
Example 4
Source File: OKEChallengeNIFTest.java    From gerbil with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) {
    for (int i = 0; i < FILES.length; i++) {
        LOGGER.info("Testing \"{}\"", FILES[i]);
        FileBasedNIFDataset dataset = new FileBasedNIFDataset(FILES[i], "", Lang.TTL);
        try {
            dataset.init();
        } catch (Exception e) {
            LOGGER.error("Exception while reading dataset.", e);
        }
        IOUtils.closeQuietly(dataset);
    }
}
 
Example 5
Source File: NIFFileDatasetConfig.java    From gerbil with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
protected Dataset loadDataset() throws Exception {
    FileBasedNIFDataset dataset = new FileBasedNIFDataset(file, getName(), Lang.TTL);
    dataset.init();
    return dataset;
}
 
Example 6
Source File: QueryOperation.java    From robot with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
/**
 * Given a Model, a SPARQL update string, an output stream, and the output format, update the
 * model and write it to the output.
 *
 * @param model Model to update
 * @param updateString SPARQL update
 * @param output output stream to write to
 * @param outputFormat the file format
 * @throws FileNotFoundException if output file cannot be found
 */
public static void runUpdate(Model model, String updateString, File output, Lang outputFormat)
    throws FileNotFoundException {
  if (outputFormat == null) {
    outputFormat = Lang.TTL;
  }
  execUpdate(model, updateString);
  writeResult(model, outputFormat, new FileOutputStream(output));
}
 
Example 7
Source File: QueryOperation.java    From robot with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
/**
 * Write a model to an output stream.
 *
 * @param model the Model to write
 * @param format the language to write in (if null, TTL)
 * @param output the output stream to write to
 */
public static void writeResult(Model model, Lang format, OutputStream output) {
  if (format == null) {
    format = Lang.TTL;
  }
  RDFDataMgr.write(output, model, format);
}