Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PO²Engine
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
PO2-Tools
PO²Engine
Commits
63b19c82
Commit
63b19c82
authored
3 years ago
by
Stephane Dervaux
Browse files
Options
Downloads
Plain Diff
Merge branch '0.9.8.2'
parents
c19a29f8
90fa7675
No related branches found
No related tags found
No related merge requests found
Pipeline
#41665
passed
3 years ago
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
pom.xml
+1
-1
1 addition, 1 deletion
pom.xml
src/main/java/fr/inrae/po2engine/model/Data.java
+166
-1
166 additions, 1 deletion
src/main/java/fr/inrae/po2engine/model/Data.java
src/main/java/fr/inrae/po2engine/model/Ontology.java
+88
-0
88 additions, 0 deletions
src/main/java/fr/inrae/po2engine/model/Ontology.java
with
255 additions
and
2 deletions
pom.xml
+
1
−
1
View file @
63b19c82
...
...
@@ -6,7 +6,7 @@
<groupId>
fr.inrae.po2engine
</groupId>
<artifactId>
PO2Engine
</artifactId>
<version>
0.9.8.
1
</version>
<version>
0.9.8.
2
</version>
<packaging>
jar
</packaging>
<properties>
...
...
This diff is collapsed.
Click to expand it.
src/main/java/fr/inrae/po2engine/model/Data.java
+
166
−
1
View file @
63b19c82
...
...
@@ -5,7 +5,10 @@ import fr.inrae.po2engine.cloudexception.CantWriteException;
import
fr.inrae.po2engine.cloudexception.LocalLockException
;
import
fr.inrae.po2engine.cloudexception.NotLoginException
;
import
fr.inrae.po2engine.externalTools.CloudConnector
;
import
fr.inrae.po2engine.externalTools.JenaTools
;
import
fr.inrae.po2engine.externalTools.RDF4JTools
;
import
fr.inrae.po2engine.model.dataModel.GeneralFile
;
import
fr.inrae.po2engine.model.dataModel.ItineraryFile
;
import
fr.inrae.po2engine.model.dataModel.MaterialsMethodsFile
;
import
fr.inrae.po2engine.model.dataModel.ProjectFile
;
import
fr.inrae.po2engine.model.partModel.MaterialMethodPart
;
...
...
@@ -17,15 +20,21 @@ import javafx.beans.property.DoubleProperty;
import
javafx.beans.property.SimpleDoubleProperty
;
import
javafx.collections.FXCollections
;
import
javafx.collections.ObservableList
;
import
javafx.util.Pair
;
import
org.apache.commons.compress.archivers.zip.ZipArchiveEntry
;
import
org.apache.commons.compress.archivers.zip.ZipFile
;
import
org.apache.commons.compress.utils.IOUtils
;
import
org.apache.commons.io.FilenameUtils
;
import
org.apache.http.auth.AuthenticationException
;
import
org.apache.jena.graph.Graph
;
import
org.apache.jena.graph.GraphMaker
;
import
org.apache.jena.graph.impl.SimpleGraphMaker
;
import
org.apache.jena.ontology.OntClass
;
import
org.apache.jena.ontology.OntModel
;
import
org.apache.jena.ontology.OntModelSpec
;
import
org.apache.jena.rdf.model.Model
;
import
org.apache.jena.rdf.model.ModelFactory
;
import
org.apache.jena.rdf.model.RDFWriter
;
import
org.apache.jena.rdf.model.Resource
;
import
org.apache.jena.vocabulary.SKOS
;
import
org.apache.logging.log4j.LogManager
;
...
...
@@ -34,6 +43,8 @@ import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import
org.apache.poi.xssf.usermodel.XSSFRow
;
import
org.apache.poi.xssf.usermodel.XSSFSheet
;
import
org.apache.poi.xssf.usermodel.XSSFWorkbook
;
import
org.eclipse.rdf4j.rio.RDFFormat
;
import
org.json.JSONArray
;
import
org.json.JSONObject
;
import
java.io.*
;
...
...
@@ -207,7 +218,13 @@ public class Data extends OntoData{
// }
public
void
setGraphModel
(
Graph
graphModel
)
{
this
.
graphModel
=
graphModel
;
this
.
dataModel
=
ModelFactory
.
createOntologyModel
(
OntModelSpec
.
OWL_MEM
,
ModelFactory
.
createModelForGraph
(
graphModel
));
}
public
OntModel
createDataModel
()
{
if
(
this
.
graphModel
!=
null
)
{
this
.
dataModel
=
ModelFactory
.
createOntologyModel
(
OntModelSpec
.
OWL_MEM
,
ModelFactory
.
createModelForGraph
(
graphModel
));
}
return
this
.
dataModel
;
}
public
Graph
getGraphModel
()
{
...
...
@@ -745,4 +762,152 @@ public class Data extends OntoData{
this
.
materialMethodFile
.
getMethodPart
().
add
(
mPart
);
}
}
public
Boolean
publish
(
JSONObject
listPath
)
{
if
(!
listPath
.
keySet
().
contains
(
"file_onto"
)
||
!
listPath
.
keySet
().
contains
(
"file_data"
)
||
!
listPath
.
keySet
().
contains
(
"onto_name"
))
{
return
false
;
}
String
projectName
=
""
;
String
repoLabel
=
""
;
projectName
=
this
.
getProjectFile
().
getNameProperty
().
getValue
();
repoLabel
=
"repository for project "
+
projectName
+
"-- Ontology used : "
+
listPath
.
getString
(
"onto_name"
);
String
projectID
=
Tools
.
normalize
(
projectName
);
try
{
RDF4JTools
.
createOrClearRepository
(
repoLabel
,
projectID
);
RDF4JTools
.
upload
(
projectID
,
"http://opendata.inra.fr/ontology/"
+
projectID
,
new
FileInputStream
(
listPath
.
getString
(
"file_onto"
)),
RDFFormat
.
TURTLE
);
RDF4JTools
.
upload
(
projectID
,
"http://opendata.inra.fr/data/"
+
projectID
,
new
FileInputStream
(
listPath
.
getString
(
"file_data"
)),
RDFFormat
.
TURTLE
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
return
false
;
}
try
{
RDF4JTools
.
setFreeReadRepository
(
projectID
,
isPublic
());
}
catch
(
AuthenticationException
|
IOException
e
)
{
e
.
printStackTrace
();
return
false
;
}
if
(
this
.
getGroup
()
!=
null
&&
!
this
.
getGroup
().
isEmpty
())
{
try
{
String
groupName
=
Tools
.
normalize
(
this
.
getGroup
());
RDF4JTools
.
replaceGraph
(
groupName
,
"http://opendata.inra.fr/data/"
+
projectID
,
new
FileInputStream
(
listPath
.
getString
(
"file_data"
)),
"http://opendata.inra.fr/ontology/ontology"
,
new
FileInputStream
(
listPath
.
getString
(
"file_onto"
)),
RDFFormat
.
TURTLE
);
RDF4JTools
.
setFreeReadRepository
(
groupName
,
isPublic
());
}
catch
(
IOException
|
AuthenticationException
e
)
{
e
.
printStackTrace
();
}
}
CloudConnector
.
addLog
(
this
,
"published"
);
RDF4JTools
.
initRepositotyInfos
(
this
);
return
true
;
}
public
JSONObject
semantize
(
Pair
<
GeneralFile
,
ArrayList
<
ItineraryFile
>>
process
,
Ontology
onto
)
throws
IOException
{
Tools
.
addProgress
(
ProgressPO2
.
PUBLISH
,
"Loading core ontology"
);
JSONObject
mess
=
new
JSONObject
();
JSONArray
error
=
new
JSONArray
();
JSONArray
listMessages
=
new
JSONArray
();
mess
.
put
(
"listMessages"
,
listMessages
);
mess
.
put
(
"error"
,
error
);
if
(!
this
.
isLoaded
().
get
())
{
error
.
put
(
"data not loaded"
);
}
if
(
this
.
isModified
())
{
error
.
put
(
"data not saved"
);
}
if
(
onto
==
null
)
{
error
.
put
(
"ontology is null"
);
}
if
(!
onto
.
isLoaded
().
get
())
{
error
.
put
(
"ontology not loaded"
);
}
if
(
onto
.
isModified
())
{
error
.
put
(
"ontology not saved"
);
}
if
(
error
.
length
()
>
0
)
{
Tools
.
delProgress
(
ProgressPO2
.
PUBLISH
);
return
mess
;
}
mess
.
put
(
"onto_name"
,
onto
.
getName
().
get
());
Tools
.
updateProgress
(
ProgressPO2
.
PUBLISH
,
"Loading core ontology"
);
OntModel
coreModel
=
JenaTools
.
ReadCoreModel
();
String
PO2_domain
=
null
;
OntModel
dataModel
=
null
;
try
{
Thread
.
sleep
(
1000
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
Tools
.
updateProgress
(
ProgressPO2
.
PUBLISH
,
"Loading domain ontology"
);
logger
.
debug
(
"Chargement de la domaine ontologie : "
+
onto
.
getName
().
get
());
OntModel
domainModel
=
JenaTools
.
ReadModel
(
onto
.
getOntologyFile
().
getAbsolutePath
());
try
{
Thread
.
sleep
(
1000
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
Tools
.
updateProgress
(
ProgressPO2
.
PUBLISH
,
"Settings NameSpaces"
);
if
(
domainModel
!=
null
)
{
logger
.
debug
(
"creating data model"
);
GraphMaker
gm
=
new
SimpleGraphMaker
();
Graph
dataGraph
=
gm
.
createGraph
(
"http://www.testnom.com"
);
this
.
setCoreModel
(
coreModel
);
this
.
setDomainModel
(
domainModel
);
this
.
setGraphModel
(
dataGraph
);
dataModel
=
this
.
createDataModel
();
dataModel
.
setNsPrefix
(
"domain"
,
this
.
getDOMAIN_NS
());
dataModel
.
setNsPrefix
(
"core"
,
this
.
getCORE_NS
());
dataModel
.
setNsPrefix
(
""
,
this
.
getDATA_NS
());
dataModel
.
setNsPrefix
(
"time"
,
"http://www.w3.org/2006/time#"
);
try
{
Thread
.
sleep
(
1000
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
Tools
.
updateProgress
(
ProgressPO2
.
PUBLISH
,
"Semantization"
,
0.0
);
File
tempFile
=
this
.
getProjectFile
().
publish
(
coreModel
,
domainModel
,
dataModel
,
listMessages
,
process
);
try
{
Thread
.
sleep
(
1000
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
Tools
.
updateProgress
(
ProgressPO2
.
PUBLISH
,
"Merge of graphs"
,
-
1.0
);
// fusion core && domain
Model
unionModel
=
coreModel
.
union
(
domainModel
);
File
tempDomain
=
File
.
createTempFile
(
"pref"
,
"ttl"
);
FileOutputStream
output
=
new
FileOutputStream
(
tempDomain
);
RDFWriter
ontologyWriter
=
unionModel
.
getWriter
(
"TTL"
);
ontologyWriter
.
write
(
unionModel
,
output
,
null
);
output
.
flush
();
mess
.
put
(
"file_onto"
,
tempDomain
.
getAbsolutePath
());
mess
.
put
(
"file_data"
,
tempFile
.
getAbsolutePath
());
try
{
Thread
.
sleep
(
1000
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
}
Tools
.
delProgress
(
ProgressPO2
.
PUBLISH
);
return
mess
;
}
}
This diff is collapsed.
Click to expand it.
src/main/java/fr/inrae/po2engine/model/Ontology.java
+
88
−
0
View file @
63b19c82
...
...
@@ -6,6 +6,7 @@ import fr.inrae.po2engine.cloudexception.LocalLockException;
import
fr.inrae.po2engine.cloudexception.NotLoginException
;
import
fr.inrae.po2engine.externalTools.CloudConnector
;
import
fr.inrae.po2engine.externalTools.JenaTools
;
import
fr.inrae.po2engine.externalTools.RDF4JTools
;
import
fr.inrae.po2engine.utils.ProgressPO2
;
import
fr.inrae.po2engine.utils.Tools
;
import
javafx.collections.FXCollections
;
...
...
@@ -14,9 +15,15 @@ import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import
org.apache.commons.compress.archivers.zip.ZipFile
;
import
org.apache.commons.compress.utils.IOUtils
;
import
org.apache.commons.io.FilenameUtils
;
import
org.apache.http.auth.AuthenticationException
;
import
org.apache.jena.ontology.OntModel
;
import
org.apache.jena.rdf.model.Model
;
import
org.apache.jena.rdf.model.RDFWriter
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
org.eclipse.rdf4j.rio.RDFFormat
;
import
org.json.JSONArray
;
import
org.json.JSONObject
;
import
java.io.*
;
import
java.net.URISyntaxException
;
...
...
@@ -405,4 +412,85 @@ public class Ontology extends OntoData{
return
listScale
;
}
public
Boolean
publish
(
JSONObject
listPath
)
{
if
(!
listPath
.
keySet
().
contains
(
"file_onto"
))
{
return
false
;
}
String
repoLabel
=
"repository for ontology "
+
this
.
getName
().
get
();
String
projectID
=
Tools
.
normalize
(
this
.
getName
().
get
());
try
{
RDF4JTools
.
createOrClearRepository
(
repoLabel
,
projectID
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
return
false
;
}
try
{
RDF4JTools
.
upload
(
projectID
,
"http://opendata.inra.fr/ontology/"
+
projectID
,
new
FileInputStream
(
listPath
.
getString
(
"file_onto"
)),
RDFFormat
.
TURTLE
);
RDF4JTools
.
setFreeReadRepository
(
projectID
,
isPublic
());
}
catch
(
AuthenticationException
|
IOException
e
)
{
e
.
printStackTrace
();
return
false
;
}
CloudConnector
.
addLog
(
this
,
"published"
);
RDF4JTools
.
initRepositotyInfos
(
this
);
return
true
;
}
public
JSONObject
semantize
()
throws
IOException
{
Tools
.
addProgress
(
ProgressPO2
.
PUBLISH
,
"Loading core ontology"
);
JSONObject
mess
=
new
JSONObject
();
JSONArray
error
=
new
JSONArray
();
mess
.
put
(
"error"
,
error
);
JSONArray
listMessages
=
new
JSONArray
();
mess
.
put
(
"listMessages"
,
listMessages
);
if
(!
this
.
isLoaded
().
get
())
{
error
.
put
(
"ontology not loaded"
);
}
if
(
this
.
isModified
())
{
error
.
put
(
"ontology not saved"
);
}
if
(
error
.
length
()
>
0
)
{
Tools
.
delProgress
(
ProgressPO2
.
PUBLISH
);
return
mess
;
}
OntModel
coreModel
=
JenaTools
.
ReadCoreModel
();
try
{
Thread
.
sleep
(
1000
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
Tools
.
updateProgress
(
ProgressPO2
.
PUBLISH
,
"Loading domain ontology"
);
OntModel
domainModel
=
JenaTools
.
ReadModel
(
ontologyFile
.
getAbsolutePath
());
try
{
Thread
.
sleep
(
1000
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
Tools
.
updateProgress
(
ProgressPO2
.
PUBLISH
,
"Settings NameSpaces"
);
Model
unionModel
=
coreModel
.
union
(
domainModel
);
File
tempDomain
=
File
.
createTempFile
(
"pref"
,
"ttl"
);
FileOutputStream
output
=
new
FileOutputStream
(
tempDomain
);
RDFWriter
ontologyWriter
=
unionModel
.
getWriter
(
"TTL"
);
ontologyWriter
.
write
(
unionModel
,
output
,
null
);
output
.
flush
();
mess
.
put
(
"file_onto"
,
tempDomain
.
getAbsolutePath
());
try
{
Thread
.
sleep
(
1000
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
Tools
.
delProgress
(
ProgressPO2
.
PUBLISH
);
return
mess
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment