当前位置: 首页>>代码示例>>Java>>正文


Java RDFParseException类代码示例

本文整理汇总了Java中org.eclipse.rdf4j.rio.RDFParseException的典型用法代码示例。如果您正苦于以下问题:Java RDFParseException类的具体用法?Java RDFParseException怎么用?Java RDFParseException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


RDFParseException类属于org.eclipse.rdf4j.rio包,在下文中一共展示了RDFParseException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: RDF4JSchemaGeneratorCore

import org.eclipse.rdf4j.rio.RDFParseException; //导入依赖的package包/类
public RDF4JSchemaGeneratorCore(String filename, RDFFormat format) throws IOException, RDFParseException {
    Path file = Paths.get(filename);
    if (!Files.exists(file)) throw new FileNotFoundException(filename);

    if (format == null) {
        format = Rio.getParserFormatForFileName(filename).orElse(null);
        log.trace("detected input format from filename {}: {}", filename, format);
    }

    try (final InputStream inputStream = Files.newInputStream(file)) {
        log.trace("Loading input file");
        model = Rio.parse(inputStream, "", format);
    }

    //import
    Set<Resource> owlOntologies = model.filter(null, RDF.TYPE, OWL.ONTOLOGY).subjects();
    if (!owlOntologies.isEmpty()) {
        setPrefix(owlOntologies.iterator().next().stringValue());
    }
}
 
开发者ID:ansell,项目名称:rdf4j-schema-generator,代码行数:21,代码来源:RDF4JSchemaGeneratorCore.java

示例2: loadResources_ThrowsException_WhenRdfDataLoadError

import org.eclipse.rdf4j.rio.RDFParseException; //导入依赖的package包/类
@Test
public void loadResources_ThrowsException_WhenRdfDataLoadError() throws Exception {
  // Arrange
  Resource resource = mock(Resource.class);
  when(resource.getInputStream()).thenThrow(new RDFParseException("message"));
  when(resource.getFilename()).thenReturn("config.trig");
  when(((ResourcePatternResolver) resourceLoader).getResources(anyString())).thenReturn(
      new Resource[] {resource});

  // Assert
  thrown.expect(ConfigurationException.class);
  thrown.expectMessage("Error while loading RDF data.");

  // Act
  backend.loadResources();
}
 
开发者ID:dotwebstack,项目名称:dotwebstack-framework,代码行数:17,代码来源:FileConfigurationBackendTest.java

示例3: performAdd

import org.eclipse.rdf4j.rio.RDFParseException; //导入依赖的package包/类
/**
 * Executes merge of triples from File
 *
 * @param file
 * @param baseURI
 * @param dataFormat
 * @param tx
 * @param contexts
 * @throws RDFParseException
 */
// performAdd
// as we use mergeGraphs, baseURI is always file.toURI
public void performAdd(File file, String baseURI, RDFFormat dataFormat, Transaction tx, Resource... contexts) throws RDFParseException {
    try {
        graphManager.setDefaultMimetype(dataFormat.getDefaultMIMEType());
        if (dataFormat.equals(RDFFormat.NQUADS) || dataFormat.equals(RDFFormat.TRIG)) {
            graphManager.mergeGraphs(new FileHandle(file),tx);
        } else {
            if (contexts.length>0) {
                for (int i = 0; i < contexts.length; i++) {
                    if(Util.notNull(contexts[i])){
                        graphManager.mergeAs(contexts[i].toString(), new FileHandle(file), getGraphPerms(),tx);
                    }else{
                        graphManager.mergeAs(DEFAULT_GRAPH_URI, new FileHandle(file), getGraphPerms(), tx);
                    }
                }
            } else {
                graphManager.mergeAs(DEFAULT_GRAPH_URI, new FileHandle(file), getGraphPerms(),tx);
            }
        }
    } catch (FailedRequestException e) {
        logger.error(e.getLocalizedMessage());
        throw new RDFParseException("Request to MarkLogic server failed, check file and format.");
    }
}
 
开发者ID:marklogic,项目名称:marklogic-rdf4j,代码行数:36,代码来源:MarkLogicClientImpl.java

示例4: testAddMalformedLiteralsStrictConfig

import org.eclipse.rdf4j.rio.RDFParseException; //导入依赖的package包/类
@Test
public void testAddMalformedLiteralsStrictConfig() throws Exception {
	Assert.assertEquals(0L, testAdminCon.size());
	Set<RioSetting<?>> empty = Collections.emptySet();
	testAdminCon.getParserConfig().setNonFatalErrors(empty);

	try {
		testAdminCon.add(MarkLogicRepositoryConnectionTest.class
				.getResourceAsStream(TEST_DIR_PREFIX + "malformed-literals.ttl"), "", RDFFormat.TURTLE);
		fail("upload of malformed literals should fail with error in strict configuration");

	} catch (Exception e) {
		Assert.assertTrue(e instanceof RDFParseException);

	}
}
 
开发者ID:marklogic,项目名称:marklogic-rdf4j,代码行数:17,代码来源:MarkLogicRepositoryConnectionTest.java

示例5: getFileContentAsStatements

import org.eclipse.rdf4j.rio.RDFParseException; //导入依赖的package包/类
/**
 * Method to read the content of a turtle file
 * 
 * @param fileName Turtle file name
 * @param baseURI
 * @return File content as a string
 */
public static List<Statement> getFileContentAsStatements(String fileName, 
        String baseURI)  {        
    List<Statement> statements = null;  
    try {
        String content = getFileContentAsString(fileName);
        StringReader reader = new StringReader(content);
        Model model;
        model = Rio.parse(reader, baseURI, FILE_FORMAT);
        Iterator<Statement> it = model.iterator();
        statements =  Lists.newArrayList(it);
    } catch (IOException | RDFParseException | 
            UnsupportedRDFormatException ex) {
        LOGGER.error("Error getting turle file",ex);          
    }         
    return statements;
}
 
开发者ID:DTL-FAIRData,项目名称:FAIRDataPoint,代码行数:24,代码来源:ExampleFilesUtils.java

示例6: getStatements

import org.eclipse.rdf4j.rio.RDFParseException; //导入依赖的package包/类
/**
 * Create List<Statements> from rdf string
 * 
 * @param rdfString     RDF string
 * @param baseUri       Base uri
 * @param format        RDF format
 * @return
 * @throws MetadataParserException 
 */
public static List<Statement> getStatements(String rdfString, IRI baseUri,
        RDFFormat format) throws MetadataParserException {
    String uri;
    if (baseUri == null) {
        uri = "http://example.com/dummyResource";
    } else {
        uri = baseUri.stringValue();
    }
    try {
        Model model = Rio.parse(new StringReader(rdfString), uri , format);
        Iterator<Statement> it = model.iterator();
        List<Statement> statements = ImmutableList.copyOf(it);
        return statements;
    } catch (RDFParseException | UnsupportedRDFormatException | 
            IOException ex) {
        String errMsg = "Error reading dataset metadata content"
                + ex.getMessage();
        LOGGER.error(errMsg);
        throw (new MetadataParserException(errMsg));
    }
}
 
开发者ID:DTL-FAIRData,项目名称:fairmetadata4j,代码行数:31,代码来源:RDFUtils.java

示例7: getFileContentAsStatements

import org.eclipse.rdf4j.rio.RDFParseException; //导入依赖的package包/类
/**
 * Method to read the content of a turtle file
 * 
 * @param fileName Turtle file name
 * @param baseURI RDF content's base uri
 * @return File content as a string
 */
public static List<Statement> getFileContentAsStatements(String fileName, 
        String baseURI)  {        
    List<Statement> statements = null;  
    try {
        String content = getFileContentAsString(fileName);
        StringReader reader = new StringReader(content);
        Model model;
        model = Rio.parse(reader, baseURI, FILE_FORMAT);
        Iterator<Statement> it = model.iterator();
        statements =  Lists.newArrayList(it);
    } catch (IOException | RDFParseException | 
            UnsupportedRDFormatException ex) {
        LOGGER.error("Error getting turle file",ex);          
    }         
    return statements;
}
 
开发者ID:DTL-FAIRData,项目名称:fairmetadata4j,代码行数:24,代码来源:ExampleFilesUtils.java

示例8: generateDataset

import org.eclipse.rdf4j.rio.RDFParseException; //导入依赖的package包/类
/**
 * Generate DCAT Dataset
 *
 * @param store RDF store
 * @param id
 * @param page full RDF XML
 * @throws MalformedURLException
 * @throws RepositoryException
 */
@Override
protected void generateDataset(Storage store, String id, Map<String, Page> page)
		throws MalformedURLException, RepositoryException {
	Page p = page.getOrDefault("", new Page());

	String xml = p.getContent();
	if (xml.isEmpty()) {
		logger.warn("Page content is empty");
		return;
	}

	// Load turtle file into store
	try (InputStream in = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8))) {
		store.add(in, RDFFormat.RDFXML);
	} catch (RDFParseException | IOException ex) {
		throw new RepositoryException(ex);
	}
}
 
开发者ID:Fedict,项目名称:dcattools,代码行数:28,代码来源:CkanRDF.java

示例9: initializeMetadata

import org.eclipse.rdf4j.rio.RDFParseException; //导入依赖的package包/类
public void initializeMetadata(Repository metadata, String filename)
        throws RepositoryException, IOException, RDFParseException
{
    RepositoryConnection conn = null;

    try {
        File file = new File(filename);
        metadata.initialize();
        conn = metadata.getConnection();
        RDFFormat fileFormat = RDFFormat.matchFileName(file.getAbsolutePath(), RDFParserRegistry.getInstance().getKeys()).orElse(RDFFormat.NTRIPLES);
        conn.add(file, file.toURI().toString(), fileFormat);
    } finally {
        if (conn != null)
            conn.close();
    }
}
 
开发者ID:semagrow,项目名称:semagrow,代码行数:17,代码来源:SemagrowSailFactory.java

示例10: startUp

import org.eclipse.rdf4j.rio.RDFParseException; //导入依赖的package包/类
@PostConstruct
public void startUp() throws IOException, RDFParseException, RDFHandlerException  {
    if(this.sparqlSamplesFile!=null){
        HashMapHandler handler = new HashMapHandler();
        RDFParser parser = Rio.createParser(RDFFormat.TURTLE);
        parser.setRDFHandler(handler);
        FileInputStream fis = null;
        try {
            fis = new FileInputStream(this.sparqlSamplesFile);
            parser.parse(fis, "");
            this.samplesData = handler.getSamplesData();
        } finally {
            if(fis!=null){
                fis.close();
            }
        }            
    }
}
 
开发者ID:semagrow,项目名称:semagrow,代码行数:19,代码来源:SparqlSamplesController.java

示例11: personLoader_givenPersonSelector_shouldLoadFourPeople

import org.eclipse.rdf4j.rio.RDFParseException; //导入依赖的package包/类
@Test
public void personLoader_givenPersonSelector_shouldLoadFourPeople() 
		throws RDFParseException, UnsupportedRDFormatException, IOException {

	Set<Person> people = RdfObjectLoader.load(selectPersons, Person.class, model);
	assertThat("4 people should be loaded", people, hasSize(4));
}
 
开发者ID:carml,项目名称:carml,代码行数:8,代码来源:RdfObjectLoaderTest.java

示例12: personLoader_givenPersonSelector_shouldLoadFourPeopleOneWithAddress

import org.eclipse.rdf4j.rio.RDFParseException; //导入依赖的package包/类
@Test
public void personLoader_givenPersonSelector_shouldLoadFourPeopleOneWithAddress() 
		throws RDFParseException, UnsupportedRDFormatException, IOException {
	
	Set<Person> people = RdfObjectLoader.load(selectPersons, Person.class, model);
	int peopleWithAddr = 
		(int) people.stream()
			.filter(p -> p.getAddress() != null)
			.count();
	
	assertThat("1 person with address should be loaded", peopleWithAddr, is(1));
}
 
开发者ID:carml,项目名称:carml,代码行数:13,代码来源:RdfObjectLoaderTest.java

示例13: addressLoader_givenAddressSelector_shouldLoadOneAddress

import org.eclipse.rdf4j.rio.RDFParseException; //导入依赖的package包/类
@Test
public void addressLoader_givenAddressSelector_shouldLoadOneAddress() 
		throws RDFParseException, UnsupportedRDFormatException, IOException {

	Set<PostalAddress> addresses = RdfObjectLoader.load(selectAddresses, PostalAddress.class, model);
	assertThat("1 address should be loaded", addresses.size(), is(1));
}
 
开发者ID:carml,项目名称:carml,代码行数:8,代码来源:RdfObjectLoaderTest.java

示例14: personLoader_givenAllResourcesSelector_shouldLoadEightPeople

import org.eclipse.rdf4j.rio.RDFParseException; //导入依赖的package包/类
@Test
public void personLoader_givenAllResourcesSelector_shouldLoadEightPeople() 
		throws RDFParseException, UnsupportedRDFormatException, IOException {

	Set<Person> people = RdfObjectLoader.load(selectAllResources, Person.class, model);
	assertThat("", people, hasSize(8));
}
 
开发者ID:carml,项目名称:carml,代码行数:8,代码来源:RdfObjectLoaderTest.java

示例15: addressLoader_givenAddressSelectorAndUpperCaseAdapter_shouldLoadAddressWithUppercaseLiterals

import org.eclipse.rdf4j.rio.RDFParseException; //导入依赖的package包/类
@Test
public void addressLoader_givenAddressSelectorAndUpperCaseAdapter_shouldLoadAddressWithUppercaseLiterals() 
		throws RDFParseException, UnsupportedRDFormatException, IOException {
	
	Set<PostalAddress> addresses = RdfObjectLoader.load(selectAddresses, PostalAddress.class, model, uppercaser);		
	PostalAddress address = Iterables.getOnlyElement(addresses);
	
	assertThat("", address.getStreetAddress(), is("1700 KRAFT DRIVE, SUITE 2408"));
	assertThat("", address.getAddressLocality(), is("BLACKSBURG"));
	assertThat("", address.getAddressRegion(), is("VA"));
	assertThat("", address.getPostalCode(), is("24060"));
}
 
开发者ID:carml,项目名称:carml,代码行数:13,代码来源:RdfObjectLoaderTest.java


注:本文中的org.eclipse.rdf4j.rio.RDFParseException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。