Skip to content

Commit

Permalink
Fuseki configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
parekhrikin committed Aug 31, 2023
1 parent d34c65d commit ede6c2e
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 0 deletions.
14 changes: 14 additions & 0 deletions eBL-backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,20 @@
<version>4.3.5</version>
</dependency>

<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-fuseki-main</artifactId>
<version>4.9.0</version> <!-- Set the version -->
</dependency>

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>


</dependencies>

<repositories>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.info7255.ebl.config;

import org.apache.jena.fuseki.main.FusekiServer;
import org.apache.jena.query.Dataset;
import org.apache.jena.tdb.TDBFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FusekiConfig {

@Value("${fuseki.port}")
private int port;

@Value("${fuseki.datasetPath}")
private String datasetPath;

@Bean(initMethod = "start", destroyMethod = "stop")
public FusekiServer fusekiServer() {
Dataset dataset = TDBFactory.createDataset(datasetPath);
return FusekiServer.create()
.port(port)
.add("/dataset", dataset)
.build();
}


}
60 changes: 60 additions & 0 deletions eBL-backend/src/main/java/com/info7255/ebl/service/Atkin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.info7255.ebl.service;

import java.util.*;

public class Atkin {

public static List<Integer> findPrimes(int limit) {
boolean[] isPrime = new boolean[limit + 1];
Arrays.fill(isPrime, false);

// 2 and 3 are known primes
isPrime[2] = true;
isPrime[3] = true;

for (int x = 1; x * x <= limit; x++) {
for (int y = 1; y * y <= limit; y++) {
int n = (4 * x * x) + (y * y);
if (n <= limit && (n % 12 == 1 || n % 12 == 5)) {
isPrime[n] = !isPrime[n];
}

n = (3 * x * x) + (y * y);
if (n <= limit && n % 12 == 7) {
isPrime[n] = !isPrime[n];
}

n = (3 * x * x) - (y * y);
if (x > y && n <= limit && n % 12 == 11) {
isPrime[n] = !isPrime[n];
}
}
}

for (int n = 5; n * n <= limit; n++) {
if (isPrime[n]) {
for (int k = n * n; k <= limit; k += n * n) {
isPrime[k] = false;
}
}
}

List<Integer> primes = new ArrayList<>();
for (int i = 2; i <= limit; i++) {
if (isPrime[i]) {
primes.add(i);
}
}

return primes;
}

public static void main(String[] args) {
int limit = 50;

List<Integer> primes = findPrimes(limit);
System.out.println("Prime numbers up to " + limit + ":");
System.out.println(primes);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.info7255.ebl.service;

import java.util.*;

public class Eratosthenes {

public static List<Integer> findPrimesInRange(int start, int end) {

boolean[] isPrime = new boolean[end + 1];
Arrays.fill(isPrime, true);

for (int i = 2; i * i <= end; i++) {
if (isPrime[i]) {
for (int j = i * i; j <= end; j += i) {
isPrime[j] = false;
}
}
}

List<Integer> primes = new ArrayList<>();
for (int i = Math.max(2, start); i <= end; i++) {
if (isPrime[i]) {
primes.add(i);
}
}

return primes;
}

public static void main(String[] args) {
int start = 10;
int end = 50;

List<Integer> primesInRange = findPrimesInRange(start, end);
System.out.println("Prime numbers between " + start + " and " + end + ":");
System.out.println(primesInRange);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@
import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.jena.fuseki.main.FusekiServer;
import org.apache.jena.rdf.model.*;
import org.apache.jena.update.UpdateExecutionFactory;
import org.apache.jena.update.UpdateFactory;
import org.apache.jena.update.UpdateProcessor;
import org.apache.jena.update.UpdateRequest;
import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.Value;
import org.eclipse.rdf4j.query.*;
Expand All @@ -38,6 +43,7 @@ public class QuoteService {

ObjectMapper objectMapper = new ObjectMapper();


private final ApplicationEventPublisher publisher;

public static QueryBank queryBank = new QueryBank();
Expand Down Expand Up @@ -132,7 +138,15 @@ public void generateRDF(JsonNode rate, Optional<User> user, JsonNode quote){

model.write(System.out, "TURTLE");

String fusekiServiceUrl = "http://localhost:3030/dataset/update";

String insertQuery = "INSERT DATA { GRAPH <http://example.com/graph> { " +
portPair +
" } }";

UpdateRequest updateRequest = UpdateFactory.create(insertQuery);
UpdateProcessor updateProcessor = UpdateExecutionFactory.createRemote(updateRequest, fusekiServiceUrl);
updateProcessor.execute();


log.info("RDF created", portPair);
Expand Down
3 changes: 3 additions & 0 deletions eBL-backend/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ rdf4j.spring.repository.remote.name=myrepo
# Optional with username and password
rdf4j.spring.repository.remote.username=admin
rdf4j.spring.repository.remote.password=1234

fuseki.port=3030
fuseki.datasetPath=/Users/rikinparekh/Repos/fuseki-server

0 comments on commit ede6c2e

Please sign in to comment.