Skip to content

Commit

Permalink
genrate and isvalideinement working for prefix transition.
Browse files Browse the repository at this point in the history
  • Loading branch information
slibhin committed Jul 25, 2010
1 parent e1bb3b6 commit c69581c
Show file tree
Hide file tree
Showing 12 changed files with 370 additions and 231 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: concurrency
level: 5
level: bon
format:
- choice (CONCURRENT):
- SEQUENTIAL
Expand All @@ -11,14 +11,14 @@ format:
- SPECIAL
- optional: <description=string=''>
scope:
- Modules
- Features
- Module
- Feature
description: |
Describes
...
---
name: concurrency
level: 2
level: java
format:
- choice (PARALLEL):
- SEQ
Expand All @@ -30,14 +30,14 @@ format:
- optional: <description=string='No information.'>
#- optional: <owner=string='unknown'>
scope:
- Modules
- Features
- Module
- Feature
description: |
Describes
...
---
property: concurrency
relation(5,2):
relation(bon,java):
- keyword:
- SEQUENTIAL: SEQ
- CONCURRENT: PARALLEL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,37 @@
import ie.ucd.semanticproperties.plugin.exceptions.UnknownLevelException;
import ie.ucd.semanticproperties.plugin.exceptions.UnknownPropertyException;
import ie.ucd.semanticproperties.plugin.exceptions.UnknownScopeException;
import ie.ucd.semanticproperties.plugin.exceptions.UnknownVariableIdentifierException;
import ie.ucd.semanticproperties.plugin.structs.SemanticPropertyLevelSpecification;
import ie.ucd.semanticproperties.plugin.structs.SemanticProperty;
import ie.ucd.semanticproperties.plugin.structs.SemanticPropertyRefinementSpecification;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

public class SemanticPropertiesHandler {

//private final specs List<SemanticPropertySpecification>;
//private final specsMap Map<String,SemanticPropertySpecification>
private final ArrayList<SemanticProperty> specs;
private final HashMap<String,SemanticProperty> specsMap ;

public SemanticPropertiesHandler() {
//TODO
specs = new ArrayList<SemanticProperty>();
specsMap = new HashMap<String , SemanticProperty>();
}

/**
* Parse the provided input file and add the property specification contained
* within the the set of known properties.
* @param propertySpecFile
* @throws IOException
*/
public void add(File propertySpecFile) throws FileNotFoundException, InvalidSemanticPropertySpecificationException {
//TODO
public void add(File propertySpecFile) throws InvalidSemanticPropertySpecificationException, IOException {
SemanticProperty temp = new SemanticProperty(propertySpecFile);
specs.add(temp);
specsMap.put(temp.getName(),temp);
}

/**
Expand All @@ -37,11 +48,20 @@ public void add(File propertySpecFile) throws FileNotFoundException, InvalidSema
* @param level
* @return
*/
public SemanticPropertyInstance parse(String input, ScopeId scope, LevelId level)
public SemanticPropertyInstance parse(String input, String name, LevelId level)
throws UnknownPropertyException, InvalidSemanticPropertyUseException,
UnknownLevelException, UnknownScopeException, SemanticPropertyNotValidAtScopeException {
//TODO
return null;

SemanticProperty temp = specsMap.get(name);
if(temp==null) {
throw new UnknownPropertyException();
}
SemanticPropertyLevelSpecification lev = temp.getLevels().get(level);
if(lev==null){
throw new UnknownLevelException();
}
SemanticPropertyInstance i = lev.makeInstance(input);
return i;
}

/**
Expand All @@ -51,11 +71,19 @@ public SemanticPropertyInstance parse(String input, ScopeId scope, LevelId level
* @param prop1
* @param prop2
* @return
* review this throws
* @throws UnknownVariableIdentifierException
*/
public boolean isValidRefinement(SemanticPropertyInstance prop1, SemanticPropertyInstance prop2)
throws IncompatibleSemanticPropertyInstancesException {
//TODO
return false;
throws IncompatibleSemanticPropertyInstancesException, UnknownVariableIdentifierException {
//doubledone
if(prop1.getPropertyType() != prop2.getPropertyType()){
throw new IncompatibleSemanticPropertyInstancesException();
}
SemanticProperty temp = specsMap.get(prop1.getPropertyType());
SemanticPropertyRefinementSpecification ref =temp.getRefinement(prop1, prop2);
return ref.isValidRefinement(prop1, prop2);

}

/**
Expand All @@ -67,8 +95,10 @@ public boolean isValidRefinement(SemanticPropertyInstance prop1, SemanticPropert
*/
public SemanticPropertyInstance generate(SemanticPropertyInstance input, LevelId level)
throws UnknownLevelException, IncompatibleSemanticPropertyInstancesException {
//TODO
return null;
SemanticProperty temp = specsMap.get(input.getPropertyType());
SemanticPropertyRefinementSpecification ref =temp.getRefinement(input.getLevel(), level);

return ref.refine(input,level);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import ie.ucd.semanticproperties.plugin.customobjects.MyObject;
import ie.ucd.semanticproperties.plugin.exceptions.UnknownVariableIdentifierException;
import ie.ucd.semanticproperties.plugin.structs.LevelRepresenation;
import ie.ucd.semanticproperties.plugin.structs.SemanticPropertyLevelSpecification;
import ie.ucd.semanticproperties.plugin.structs.RegExpStruct;

public class SemanticPropertyInstance {
Expand All @@ -16,30 +16,18 @@ public class SemanticPropertyInstance {
private ArrayList<ScopeId> scope;
private String propId;
private HashMap<String,Object> captured;
private String input;
//TODO args to constructor (Map<String,?>,propId,scope,level)
public SemanticPropertyInstance(String input,LevelRepresenation propIn) {
//scope might not be needed
public SemanticPropertyInstance(String input, String name, LevelId level, ArrayList<ScopeId> scope,HashMap<String, Object> map) {
/**
* Assign scope, level and Id.
*/
scope = propIn.getScope();
level = propIn.getLevel();
propId = propIn.getName();
/**
* Match Instance
*/
Pattern p = Pattern.compile(propIn.getReg().getExp());
Matcher m = p.matcher(input);
/**
* Fill HashMap with the captured variables for this Instance.
*/
HashMap<String, Integer> intMap = propIn.getReg().getGroupInt();
HashMap<String, MyObject> obMap = propIn.getReg().getGroupObj();
for(String s:intMap.keySet()) {

MyObject ob = obMap.get(s);
ob.setValue(m.group(intMap.get(s)));
captured.put(s, ob.getValue());
}
this.input=input;
this.scope = scope;
this.level = level;
this.propId = name;
this.captured = map;

}

Expand Down Expand Up @@ -76,4 +64,12 @@ public String toString() {
return null;
}

public HashMap<String, Object> getCaptured() {
return captured;
}

public String getInput() {
return input;
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ie.ucd.semanticproperties.plugin.example;

import ie.ucd.semanticproperties.plugin.structs.Refinement;
import ie.ucd.semanticproperties.plugin.structs.SemanticPropertyRefinementSpecification;
import ie.ucd.semanticproperties.plugin.yaml.CustomConstructor;
import ie.ucd.semanticproperties.plugin.yaml.CustomRepresenter;
import ie.ucd.semanticproperties.plugin.yaml.CustomResolver;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ public class LevelRepMatch {

private String inputToMatch;
private Matcher thisMatch;
LevelRepresenation prop;
SemanticPropertyLevelSpecification prop;
Boolean isMatch;

/**
*
* @param input
* @param prop
*/
public LevelRepMatch(String input,LevelRepresenation propIn){
public LevelRepMatch(String input,SemanticPropertyLevelSpecification propIn){
prop = propIn;
inputToMatch = input;
Pattern p = Pattern.compile(propIn.getReg().getExp());
Expand Down Expand Up @@ -59,7 +59,7 @@ public MyObject getVar(String in) {
}

}
public LevelRepresenation getProp() {
public SemanticPropertyLevelSpecification getProp() {
return prop;
}
public Matcher getMatch() {
Expand Down
Loading

0 comments on commit c69581c

Please sign in to comment.