Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
histream
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Raphael
histream
Commits
5039a9dd
Commit
5039a9dd
authored
Aug 02, 2016
by
R.W.Majeed
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
require disjoint concepts
parent
3c465044
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
0 deletions
+53
-0
histream-export/src/main/java/de/sekmi/histream/export/TableExport.java
...t/src/main/java/de/sekmi/histream/export/TableExport.java
+53
-0
No files found.
histream-export/src/main/java/de/sekmi/histream/export/TableExport.java
View file @
5039a9dd
...
...
@@ -2,6 +2,8 @@ package de.sekmi.histream.export;
import
java.io.IOException
;
import
java.io.UncheckedIOException
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.function.Consumer
;
import
javax.xml.namespace.NamespaceContext
;
...
...
@@ -12,6 +14,7 @@ import javax.xml.xpath.XPathFactory;
import
de.sekmi.histream.ObservationException
;
import
de.sekmi.histream.ObservationSupplier
;
import
de.sekmi.histream.export.config.Concept
;
import
de.sekmi.histream.export.config.ExportDescriptor
;
import
de.sekmi.histream.export.config.ExportException
;
import
de.sekmi.histream.io.Streams
;
...
...
@@ -55,6 +58,55 @@ public class TableExport {
xpath
.
setNamespaceContext
(
ns
);
return
xpath
;
}
/**
* Make sure, that any intersection between groups are empty.
* Overlapping group means concepts would get multiple classes
* assigned, which is not supported at this time.
*
* @throws ExportException if there are overlapping concepts
*/
private
void
requireDisjointConcepts
()
throws
ExportException
{
// easier: require unique concepts and no overlapping wildcards
List
<
String
>
prefixes
=
new
ArrayList
<>();
List
<
String
>
notations
=
new
ArrayList
<>();
for
(
Concept
concept
:
desc
.
allConcepts
()
){
String
s
=
concept
.
getNotation
();
if
(
s
!=
null
){
notations
.
add
(
s
);
}
s
=
concept
.
getWildcardNotation
();
if
(
s
!=
null
){
// wildcard must end with *
if
(
s
.
indexOf
(
'*'
)
!=
s
.
length
()-
1
){
throw
new
ExportException
(
"Illegal wildcard notation: "
+
s
);
}
prefixes
.
add
(
s
.
substring
(
0
,
s
.
length
()-
1
));
}
}
// make sure prefixes do not overlap
// a can overlap b only, if a.length <= b.length
// sort prefixes by length
prefixes
.
sort
(
(
a
,
b
)
->
a
.
length
()
-
b
.
length
()
);
for
(
int
i
=
0
;
i
<
prefixes
.
size
();
i
++
){
String
a
=
prefixes
.
get
(
i
);
for
(
int
j
=
i
+
1
;
j
<
prefixes
.
size
();
j
++
){
String
b
=
prefixes
.
get
(
j
);
if
(
b
.
startsWith
(
a
)
){
throw
new
ExportException
(
"Illegal overlapping of wildcard notations '"
+
a
+
"*' and '"
+
b
+
"*"
);
}
}
}
// check if prefix matches any notations
for
(
String
prefix
:
prefixes
){
for
(
String
notation
:
notations
){
if
(
notation
.
startsWith
(
prefix
)
){
throw
new
ExportException
(
"Concepts not unique: wildcard '"
+
prefix
+
"*' matches notation '"
+
notation
+
"'"
);
}
}
}
// TODO check for unique notations
}
/**
* Export all observations by the given supplier to the specified {@link ExportWriter}.
* <p>
...
...
@@ -68,6 +120,7 @@ public class TableExport {
* @throws IOException IO exception
*/
public
void
export
(
ObservationSupplier
supplier
,
ExportWriter
writer
)
throws
ExportException
,
IOException
{
requireDisjointConcepts
();
try
(
FragmentExporter
e
=
new
FragmentExporter
(
createXPath
(),
desc
,
writer
)
){
e
.
setErrorHandler
(
new
ExportErrorHandler
());
Streams
.
transfer
(
supplier
,
e
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment