Skip to content

Commit f97c0d0

Browse files
authored
Label generator code for tollbooth demo (#873)
* quick outline of label generator * temp file with pl/sql to create kafka topic --------- Signed-off-by: Mark Nelson <mark.x.nelson@oracle.com>
1 parent c359f60 commit f97c0d0

File tree

11 files changed

+4526
-0
lines changed

11 files changed

+4526
-0
lines changed

tolldemo/TEMP

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
create user tolldemo identified by Welcome12345;
2+
grant resource, connect, unlimited tablespace to tolldemo;
3+
grant execute on dbms_aq to tolldemo;
4+
grant execute on dbms_aqadm to tolldemo;
5+
grant execute on dbms_aqin to tolldemo;
6+
grant execute on dbms_aqjms_internal to tolldemo;
7+
grant execute on dbms_teqk to tolldemo;
8+
grant execute on DBMS_RESOURCE_MANAGER to tolldemo;
9+
grant select_catalog_role to tolldemo;
10+
grant select on sys.aq$_queue_shards to tolldemo;
11+
grant select on user_queue_partition_assignment_table to tolldemo;
12+
exec dbms_teqk.AQ$_GRANT_PRIV_FOR_REPL('TOLLDEMO');
13+
commit;
14+
15+
connect tolldemo/Welcome12345
16+
17+
begin
18+
dbms_awadm.create_sharded_queue (queue_name => 'TollGate', multiple_consumers => true);
19+
dbms_awadm.set_queue_parameter(tname, 'KEY_BASED_ENQUEUE', 2);
20+
dbms_awadm.set_queue_parameter(tname, 'SHARD_NUM', 5);
21+
dbms_awadm.start_queue(tname) ;
22+
end;

tolldemo/label-generator/pom.xml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>org.springframework.boot</groupId>
7+
<artifactId>spring-boot-starter-parent</artifactId>
8+
<version>3.2.4</version>
9+
<relativePath/> <!-- lookup parent from repository -->
10+
</parent>
11+
<groupId>com.example</groupId>
12+
<artifactId>label-generator</artifactId>
13+
<version>0.0.1-SNAPSHOT</version>
14+
<name>label-generator</name>
15+
<description>Demo project for Spring Boot</description>
16+
<properties>
17+
<java.version>17</java.version>
18+
</properties>
19+
<dependencies>
20+
<dependency>
21+
<groupId>org.springframework.boot</groupId>
22+
<artifactId>spring-boot-starter</artifactId>
23+
</dependency>
24+
25+
<dependency>
26+
<groupId>org.springframework.boot</groupId>
27+
<artifactId>spring-boot-starter-test</artifactId>
28+
<scope>test</scope>
29+
</dependency>
30+
</dependencies>
31+
32+
<build>
33+
<plugins>
34+
<plugin>
35+
<groupId>org.springframework.boot</groupId>
36+
<artifactId>spring-boot-maven-plugin</artifactId>
37+
</plugin>
38+
</plugins>
39+
</build>
40+
41+
</project>
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package com.example.labelgenerator;
2+
3+
import java.io.BufferedReader;
4+
import java.io.BufferedWriter;
5+
import java.io.FileReader;
6+
import java.io.FileWriter;
7+
import java.io.IOException;
8+
9+
import org.springframework.boot.CommandLineRunner;
10+
import org.springframework.boot.SpringApplication;
11+
import org.springframework.boot.autoconfigure.SpringBootApplication;
12+
13+
@SpringBootApplication
14+
public class LabelGeneratorApplication implements CommandLineRunner {
15+
16+
private static final String outputFile = "target/cars.jsonl";
17+
private static final String inputFile = "src/main/resources/input-files.txt";
18+
19+
public static void main(String[] args) {
20+
SpringApplication.run(LabelGeneratorApplication.class, args);
21+
}
22+
23+
@Override
24+
public void run(String... args) {
25+
// do the things
26+
27+
// open input and output files
28+
try (
29+
BufferedWriter writer = new BufferedWriter(new FileWriter(outputFile));
30+
BufferedReader reader = new BufferedReader(new FileReader(inputFile))
31+
) {
32+
33+
// write header to output
34+
writer.write(header);
35+
36+
// iterate through input a line at a time
37+
String line;
38+
while ((line = reader.readLine()) != null) {
39+
// for each line, write out record, substitute path and type
40+
String type = line.split("/")[1];
41+
writer.write(record.replace("XX_PATH_XX", line).replace("XX_TYPE_XX", type));
42+
}
43+
44+
} catch (IOException e) {
45+
// ignore
46+
}
47+
48+
}
49+
50+
private static final String header = """
51+
{
52+
"labelsSet": [{ "name": "type" }],
53+
"annotationFormat": "SINGLE_LABEL",
54+
"datasetFormatDetails": { "formatType": "TEXT" }
55+
}
56+
""";
57+
58+
private static final String record = """
59+
{
60+
"sourceDetails": { "path": "XX_PATH_XX" },
61+
"annotations": [
62+
{
63+
"entities": [
64+
{
65+
"entityType": "GENERIC",
66+
"labels": [{ "type": "XX_TYPE_XX" }]
67+
}
68+
]
69+
}
70+
]
71+
}
72+
""";
73+
74+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
spring.application.name=label-generator
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"labelsSet": [{ "name": "type" }],
3+
"annotationFormat": "SINGLE_LABEL",
4+
"datasetFormatDetails": { "formatType": "TEXT" }
5+
}
6+
7+
{
8+
"sourceDetails": { "path": "<Path of text record file>" },
9+
"annotations": [
10+
{
11+
"entities": [
12+
{
13+
"entityType": "GENERIC",
14+
"labels": [{ "type": "sedan" }]
15+
}
16+
]
17+
}
18+
]
19+
}

0 commit comments

Comments
 (0)