ADD : RDF Conn Test
This commit is contained in:
		
							
								
								
									
										11
									
								
								pom.xml
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								pom.xml
									
									
									
									
									
								
							| @@ -14,6 +14,17 @@ | |||||||
|             <type>pom</type> |             <type>pom</type> | ||||||
|             <version>3.16.0</version> |             <version>3.16.0</version> | ||||||
|         </dependency> |         </dependency> | ||||||
|  |         <dependency> | ||||||
|  |             <groupId>org.apache.jena</groupId> | ||||||
|  |             <artifactId>jena-fuseki-war</artifactId> | ||||||
|  |             <type>war</type> | ||||||
|  |             <version>3.16.0</version> | ||||||
|  |         </dependency> | ||||||
|  |         <dependency> | ||||||
|  |             <groupId>org.apache.jena</groupId> | ||||||
|  |             <artifactId>jena-fuseki-main</artifactId> | ||||||
|  |             <version>3.16.0</version> | ||||||
|  |         </dependency> | ||||||
|     </dependencies> |     </dependencies> | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										24
									
								
								src/main/java/RDFConnectionExample.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								src/main/java/RDFConnectionExample.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,24 @@ | |||||||
|  | import org.apache.jena.query.*; | ||||||
|  | import org.apache.jena.query.ResultSetFormatter; | ||||||
|  | import org.apache.jena.rdfconnection.RDFConnection; | ||||||
|  | import org.apache.jena.rdfconnection.RDFConnectionFactory; | ||||||
|  | import org.apache.jena.system.Txn; | ||||||
|  |  | ||||||
|  | public class RDFConnectionExample { | ||||||
|  |     public static void main(String ...args) { | ||||||
|  |         Query query = QueryFactory.create("SELECT * { {?s ?p ?o } UNION { GRAPH ?g { ?s ?p ?o } } }"); | ||||||
|  |         Dataset dataset = DatasetFactory.createTxnMem(); | ||||||
|  |         RDFConnection conn = RDFConnectionFactory.connect(dataset); | ||||||
|  |  | ||||||
|  |         Txn.executeWrite(conn, () ->{ | ||||||
|  |             System.out.println("Load a file"); | ||||||
|  |             conn.load("data.ttl"); | ||||||
|  |             conn.load("http://localhost:3030/GGD", "data.ttl"); | ||||||
|  |             System.out.println("In write transaction"); | ||||||
|  |             conn.queryResultSet(query, ResultSetFormatter::out); | ||||||
|  |         }); | ||||||
|  |         // And again - implicit READ transaction. | ||||||
|  |         System.out.println("After write transaction"); | ||||||
|  |         conn.queryResultSet(query, ResultSetFormatter::out); | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -1,2 +1,28 @@ | |||||||
|  |  | ||||||
|  | import org.apache.jena.rdf.model.Model; | ||||||
|  | import org.apache.jena.rdf.model.ModelFactory; | ||||||
|  | import org.apache.jena.rdf.model.Resource; | ||||||
|  | import org.apache.jena.vocabulary.VCARD; | ||||||
|  |  | ||||||
| public class main { | public class main { | ||||||
|  |     public static void main(String args[]){ | ||||||
|  |         String personURI    = "http://localhost:8080/JohnSmith"; | ||||||
|  |         String givenName    = "John"; | ||||||
|  |         String familyName   = "Smith"; | ||||||
|  |         String fullName     = givenName + " " + familyName; | ||||||
|  |  | ||||||
|  |         // create an empty model | ||||||
|  |         Model model = ModelFactory.createDefaultModel(); | ||||||
|  |  | ||||||
|  |         // create the resource | ||||||
|  |         //   and add the properties cascading style | ||||||
|  |         Resource johnSmith  = model.createResource(personURI) | ||||||
|  |                 .addProperty(VCARD.FN, fullName) | ||||||
|  |                 .addProperty(VCARD.N, | ||||||
|  |                         model.createResource() | ||||||
|  |                                 .addProperty(VCARD.Given, givenName) | ||||||
|  |                                 .addProperty(VCARD.Family, familyName)); | ||||||
|  |  | ||||||
|     } |     } | ||||||
|  |     } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user