Skip to content
This repository has been archived by the owner on Jan 20, 2022. It is now read-only.

Commit

Permalink
PMML : Initial separation of informer from main PMML module
Browse files Browse the repository at this point in the history
  • Loading branch information
sotty committed Aug 7, 2013
1 parent 5d43973 commit 159d47b
Showing 1 changed file with 20 additions and 16 deletions.
Expand Up @@ -248,7 +248,7 @@ public PMML4Compiler() {



private static void initVisitor() throws IOException {
private static void initVisitor( PMML pmml ) throws IOException {
RuleBaseConfiguration conf = new RuleBaseConfiguration();
conf.setEventProcessingMode( EventProcessingOption.STREAM );
//conf.setConflictResolver(LifoConflictResolver.getInstance());
Expand All @@ -264,13 +264,13 @@ private static void initVisitor() throws IOException {
kBuilder.add( ResourceFactory.newClassPathResource( COMPILER_RULES ), ResourceType.DRL );
compilerRules = true;
}
if ( informerRules == false ) {
if ( informerRules == false && needsInformerExtension( pmml ) ) {
Resource res = ResourceFactory.newClassPathResource( INFORMER_RULES, PMML4Compiler.class );
try {
if ( res != null && new File( (( ClassPathResource) res).getURL().toURI() ).exists() ) {
if ( res != null && (( ClassPathResource) res).getURL().openConnection().getContentType() != null ) {
kBuilder.add( res, ResourceType.DRL );
}
} catch ( URISyntaxException e ) {
} catch ( IOException e ) {
throw new IOException( "Unable to check for informer rules " + e.getMessage() );
}
informerRules = true;
Expand Down Expand Up @@ -349,7 +349,7 @@ private static void checkBuildingResources( PMML pmml ) throws IOException {
initRegistry();
}
if ( visitor == null ) {
initVisitor();
initVisitor( pmml );
}

for ( Object o : pmml.getAssociationModelsAndBaselineModelsAndClusteringModels() ) {
Expand Down Expand Up @@ -398,6 +398,17 @@ private static void checkBuildingResources( PMML pmml ) throws IOException {
}
}

if ( ! informerLoaded && needsInformerExtension( pmml ) ) {
for ( String ntempl : INFORMER_TEMPLATES ) {
prepareTemplate( ntempl );
}
informerLoaded = true;
}

}


protected static boolean needsInformerExtension( PMML pmml ) {
for ( Object o : pmml.getAssociationModelsAndBaselineModelsAndClusteringModels() ) {
List inner;
if ( o instanceof AssociationModel ) {
Expand Down Expand Up @@ -440,24 +451,17 @@ private static void checkBuildingResources( PMML pmml ) throws IOException {
if ( p instanceof Extension ) {
Extension x = (Extension) p;
for ( Object c : x.getContent() ) {
if ( ! informerLoaded && c instanceof Element && ((Element) c).getTagName().equals( "Surveyable" ) ) {
for ( String ntempl : INFORMER_TEMPLATES ) {
prepareTemplate( ntempl );
}
informerLoaded = true;
if ( c instanceof Element && ((Element) c).getTagName().equals( "Surveyable" ) ) {
return true;
}
}
}
}
}




}
return false;
}



private static void prepareTemplate( String ntempl ) {
try {
String path = TEMPLATE_PATH + ntempl;
Expand Down

0 comments on commit 159d47b

Please sign in to comment.