Search in sources :

Example 16 with SchemaVertexType

use of au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType in project constellation by constellation-app.

the class CreateVertexTypePlugin method edit.

@Override
public void edit(final GraphWriteMethods graph, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException {
    final String name = parameters.getStringValue(NAME_PARAMETER_ID);
    if (name == null) {
        throw new IllegalArgumentException("A name must be supplied");
    }
    final String description = parameters.getStringValue(DESCRIPTION_PARAMETER_ID);
    if (description == null) {
        throw new IllegalArgumentException("A description must be supplied");
    }
    final ConstellationColor color = parameters.getColorValue(COLOR_PARAMETER_ID);
    final String fgIconName = parameters.getStringValue(FG_ICON_PARAMETER_ID);
    final ConstellationIcon foregroundIcon = IconManager.getIcon(fgIconName);
    final String bgIconName = parameters.getStringValue(BG_ICON_PARAMETER_ID);
    final ConstellationIcon backgroundIcon = IconManager.getIcon(bgIconName);
    final String dregex = parameters.getStringValue(DETECTION_REGEX_PARAMETER_ID);
    final Pattern detectionRegex = dregex != null ? Pattern.compile(dregex, Pattern.CASE_INSENSITIVE) : null;
    final String vregex = parameters.getStringValue(VALIDATION_REGEX_PARAMETER_ID);
    final Pattern validationRegex = vregex != null ? Pattern.compile(vregex, Pattern.CASE_INSENSITIVE) : null;
    final String stype = parameters.getStringValue(SUPER_TYPE_PARAMETER_ID);
    final SchemaVertexType superType = stype != null ? SchemaVertexTypeUtilities.getType(stype) : null;
    final String otype = parameters.getStringValue(OVERRIDDEN_TYPE_PARAMETER_ID);
    final SchemaVertexType overridenType = otype != null ? SchemaVertexTypeUtilities.getType(otype) : null;
    final boolean incomplete = parameters.getBooleanValue(INCOMPLETE_PARAMETER_ID);
    final Map<String, String> properties = null;
    final SchemaVertexType svt = new SchemaVertexType(name, description, color, foregroundIcon, backgroundIcon, detectionRegex, validationRegex, superType, overridenType, properties, incomplete);
    SchemaVertexTypeUtilities.addCustomType(svt, true);
}
Also used : ConstellationColor(au.gov.asd.tac.constellation.utilities.color.ConstellationColor) Pattern(java.util.regex.Pattern) SchemaVertexType(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType) ConstellationIcon(au.gov.asd.tac.constellation.utilities.icon.ConstellationIcon)

Example 17 with SchemaVertexType

use of au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType in project constellation by constellation-app.

the class AnalyticSchemaV2UpdateProvider method schemaUpdate.

@Override
protected void schemaUpdate(final StoreGraph graph) {
    boolean updateVertexKeys = false;
    // update vertex raw attribute
    final int oldVertexRawAttributeId = AnalyticConcept.VertexAttribute.RAW.get(graph);
    final Attribute oldVertexRawAttribute = new GraphAttribute(graph, oldVertexRawAttributeId);
    if (!oldVertexRawAttribute.getAttributeType().equals(RawAttributeDescription.ATTRIBUTE_NAME)) {
        graph.setPrimaryKey(GraphElementType.VERTEX);
        final int newVertexRawAttribute = AnalyticConcept.VertexAttribute.RAW.ensure(graph);
        final int vertexIdentifierAttribute = VisualConcept.VertexAttribute.IDENTIFIER.ensure(graph);
        for (int vertexPosition = 0; vertexPosition < graph.getVertexCount(); vertexPosition++) {
            final int vertexId = graph.getVertex(vertexPosition);
            final String rawValue = graph.getStringValue(oldVertexRawAttributeId, vertexId);
            graph.setObjectValue(newVertexRawAttribute, vertexId, new RawData(rawValue, null));
            if (graph.getStringValue(vertexIdentifierAttribute, vertexId) == null) {
                graph.setObjectValue(vertexIdentifierAttribute, vertexId, rawValue);
            }
        }
        graph.removeAttribute(oldVertexRawAttributeId);
        updateVertexKeys = true;
    }
    // update vertex type attribute
    if (AnalyticConcept.VertexAttribute.TYPE.get(graph) == Graph.NOT_FOUND) {
        updateVertexKeys = true;
    }
    final int oldVertexTypeAttributeId = graph.getAttribute(GraphElementType.VERTEX, "Type");
    final Attribute oldVertexTypeAttribute = new GraphAttribute(graph, oldVertexTypeAttributeId);
    if (!oldVertexTypeAttribute.getAttributeType().equals(VertexTypeAttributeDescription.ATTRIBUTE_NAME)) {
        graph.setPrimaryKey(GraphElementType.VERTEX);
        final int newVertexTypeAttributeId = AnalyticConcept.VertexAttribute.TYPE.ensure(graph);
        final int vertexRawAttributeId = AnalyticConcept.VertexAttribute.RAW.ensure(graph);
        for (int vertexPosition = 0; vertexPosition < graph.getVertexCount(); vertexPosition++) {
            final int vertexId = graph.getVertex(vertexPosition);
            final String typeValue = graph.getStringValue(oldVertexTypeAttributeId, vertexId);
            final SchemaVertexType type = SchemaVertexTypeUtilities.getType(typeValue);
            graph.setObjectValue(newVertexTypeAttributeId, graph.getVertex(vertexPosition), type);
            final RawData rawValue = graph.getObjectValue(vertexRawAttributeId, graph.getVertex(vertexPosition));
            graph.setObjectValue(vertexRawAttributeId, vertexId, rawValue != null ? new RawData(rawValue.getRawIdentifier(), typeValue) : new RawData(null, null));
        }
        graph.removeAttribute(oldVertexTypeAttributeId);
        updateVertexKeys = true;
    }
    // update vertex keys and complete vertices
    if (updateVertexKeys && graph.getSchema() != null) {
        final List<SchemaAttribute> keyAttributes = graph.getSchema().getFactory().getKeyAttributes(GraphElementType.VERTEX);
        final int[] keyAttributeIds = keyAttributes.stream().map(keyAttribute -> keyAttribute.ensure(graph)).mapToInt(keyAttributeId -> keyAttributeId).toArray();
        graph.setPrimaryKey(GraphElementType.VERTEX, keyAttributeIds);
    }
    boolean updateTransactionKeys = false;
    // update transaction type attribute
    if (AnalyticConcept.TransactionAttribute.TYPE.get(graph) == Graph.NOT_FOUND) {
        updateTransactionKeys = true;
    }
    final int oldTransactionTypeAttributeId = graph.getAttribute(GraphElementType.TRANSACTION, "Type");
    final Attribute oldTransactionTypeAttribute = new GraphAttribute(graph, oldTransactionTypeAttributeId);
    if (!oldTransactionTypeAttribute.getAttributeType().equals(TransactionTypeAttributeDescription.ATTRIBUTE_NAME)) {
        graph.setPrimaryKey(GraphElementType.TRANSACTION);
        final int newTransactionTypeAttributeId = AnalyticConcept.TransactionAttribute.TYPE.ensure(graph);
        for (int transactionPosition = 0; transactionPosition < graph.getTransactionCount(); transactionPosition++) {
            final int transactionId = graph.getTransaction(transactionPosition);
            final String typeValue = graph.getStringValue(oldTransactionTypeAttributeId, transactionId);
            final SchemaTransactionType type = SchemaTransactionTypeUtilities.getType(typeValue);
            graph.setObjectValue(newTransactionTypeAttributeId, transactionId, type);
        }
        graph.removeAttribute(oldTransactionTypeAttributeId);
        updateTransactionKeys = true;
    }
    // update transaction datetime attribute
    if (TemporalConcept.TransactionAttribute.DATETIME.get(graph) == Graph.NOT_FOUND) {
        updateTransactionKeys = true;
    }
    // update transaction keys and complete transactions
    if (updateTransactionKeys && graph.getSchema() != null) {
        final List<SchemaAttribute> keyAttributes = graph.getSchema().getFactory().getKeyAttributes(GraphElementType.TRANSACTION);
        final int[] keyAttributeIds = keyAttributes.stream().map(keyAttribute -> keyAttribute.ensure(graph)).mapToInt(keyAttributeId -> keyAttributeId).toArray();
        graph.setPrimaryKey(GraphElementType.TRANSACTION, keyAttributeIds);
    }
}
Also used : RawData(au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.RawData) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) AnalyticSchemaFactory(au.gov.asd.tac.constellation.graph.schema.analytic.AnalyticSchemaFactory) SchemaTransactionType(au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType) SchemaVertexTypeUtilities(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexTypeUtilities) UpdateProvider(au.gov.asd.tac.constellation.graph.versioning.UpdateProvider) RawAttributeDescription(au.gov.asd.tac.constellation.graph.schema.analytic.attribute.RawAttributeDescription) TransactionTypeAttributeDescription(au.gov.asd.tac.constellation.graph.schema.analytic.attribute.TransactionTypeAttributeDescription) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) VertexTypeAttributeDescription(au.gov.asd.tac.constellation.graph.schema.analytic.attribute.VertexTypeAttributeDescription) SchemaTransactionTypeUtilities(au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionTypeUtilities) SchemaUpdateProvider(au.gov.asd.tac.constellation.graph.versioning.SchemaUpdateProvider) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) SchemaFactory(au.gov.asd.tac.constellation.graph.schema.SchemaFactory) VisualConcept(au.gov.asd.tac.constellation.graph.schema.visual.concept.VisualConcept) Graph(au.gov.asd.tac.constellation.graph.Graph) SchemaVertexType(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType) List(java.util.List) SchemaFactoryUtilities(au.gov.asd.tac.constellation.graph.schema.SchemaFactoryUtilities) AnalyticConcept(au.gov.asd.tac.constellation.graph.schema.analytic.concept.AnalyticConcept) RawData(au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.RawData) TemporalConcept(au.gov.asd.tac.constellation.graph.schema.analytic.concept.TemporalConcept) ServiceProvider(org.openide.util.lookup.ServiceProvider) Attribute(au.gov.asd.tac.constellation.graph.Attribute) SchemaAttribute(au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute) SchemaTransactionType(au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType) SchemaVertexType(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) Attribute(au.gov.asd.tac.constellation.graph.Attribute) SchemaAttribute(au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) SchemaAttribute(au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute)

Example 18 with SchemaVertexType

use of au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType in project constellation by constellation-app.

the class VertexTypeIOProvider method readTypeObject.

private static SchemaVertexType readTypeObject(final JsonNode type) throws IOException {
    final JsonNode name = type.get(NAME_FIELD);
    final JsonNode description = type.get(DESCRIPTION_FIELD);
    final JsonNode color = type.get(COLOR_FIELD);
    final JsonNode foregroundIcon = type.get(FOREGROUND_ICON_FIELD);
    final JsonNode backgroundIcon = type.get(BACKGROUND_ICON_FIELD);
    final JsonNode detectRegex = type.get(DETECTION_REGEX_FIELD);
    final JsonNode validationRegex = type.get(VALIDATION_REGEX_FIELD);
    final JsonNode superType = type.get(SUPERTYPE_FIELD);
    final JsonNode overriddenType = type.get(OVERRIDDEN_TYPE_FIELD);
    final JsonNode properties = type.get(PROPERTIES_FIELD);
    final JsonNode incomplete = type.get(INCOMPLETE_FIELD);
    final Map<String, String> props = new HashMap<>();
    if (!properties.isNull() && properties.isObject()) {
        final Iterator<String> keys = properties.fieldNames();
        while (keys.hasNext()) {
            final String key = keys.next();
            final JsonNode value = properties.get(key);
            props.put(key, value.isNull() ? null : value.textValue());
        }
    }
    // TODO: need to serialise the pattern case sensitivity
    final SchemaVertexType schemaVertexType = new SchemaVertexType.Builder(name.textValue()).setDescription(description == null ? null : description.textValue()).setColor(color == null ? null : readColorObject(color)).setForegroundIcon(foregroundIcon == null ? null : IconManager.getIcon(foregroundIcon.textValue())).setBackgroundIcon(backgroundIcon == null ? null : IconManager.getIcon(backgroundIcon.textValue())).setDetectionRegex(detectRegex == null ? null : Pattern.compile(detectRegex.textValue(), Pattern.CASE_INSENSITIVE)).setValidationRegex(validationRegex == null ? null : Pattern.compile(validationRegex.textValue(), Pattern.CASE_INSENSITIVE)).setSuperType(superType == null ? null : readTypeObject(superType)).setOverridenType(overriddenType == null ? null : readTypeObject(overriddenType)).setProperties(props).setIncomplete(incomplete == null ? null : incomplete.booleanValue()).build();
    final SchemaVertexType singletonType = SchemaVertexTypeUtilities.getType(schemaVertexType.getName());
    return schemaVertexType.equals(singletonType) ? singletonType : schemaVertexType;
}
Also used : SchemaVertexType(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType) HashMap(java.util.HashMap) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 19 with SchemaVertexType

use of au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType in project constellation by constellation-app.

the class ExtractTypesFromTextPlugin method query.

@Override
protected RecordStore query(final RecordStore query, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
    final RecordStore result = new GraphRecordStore();
    interaction.setProgress(0, 0, "Importing...", true);
    final Map<String, PluginParameter<?>> extractEntityParameters = parameters.getParameters();
    final String text = extractEntityParameters.get(TEXT_PARAMETER_ID).getStringValue();
    if (text == null) {
        throw new PluginException(PluginNotificationLevel.ERROR, "No text provided from which to extract types.");
    }
    final List<ExtractedVertexType> extractedTypes = SchemaVertexTypeUtilities.extractVertexTypes(text);
    final Map<String, SchemaVertexType> identifiers = new HashMap<>();
    extractedTypes.forEach(extractedType -> identifiers.put(extractedType.getIdentifier(), extractedType.getType()));
    for (final String identifier : identifiers.keySet()) {
        result.add();
        result.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.IDENTIFIER, identifier);
        result.set(GraphRecordStoreUtilities.SOURCE + AnalyticConcept.VertexAttribute.TYPE, identifiers.get(identifier));
        result.set(GraphRecordStoreUtilities.SOURCE + AnalyticConcept.VertexAttribute.SEED, "true");
    }
    ConstellationLoggerHelper.createPropertyBuilder(this, result.getAll(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.IDENTIFIER), ConstellationLoggerHelper.SUCCESS);
    interaction.setProgress(1, 0, "Completed successfully - imported " + result.size() + " entities.", true);
    return result;
}
Also used : SchemaVertexType(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType) HashMap(java.util.HashMap) RecordStore(au.gov.asd.tac.constellation.graph.processing.RecordStore) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) ExtractedVertexType(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexTypeUtilities.ExtractedVertexType)

Example 20 with SchemaVertexType

use of au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType in project constellation by constellation-app.

the class ExtractWordsFromTextPlugin method edit.

@Override
public void edit(final GraphWriteMethods wg, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
    interaction.setProgress(0, 0, "Extracting...", true);
    /*
         Retrieving attributes
         */
    final Map<String, PluginParameter<?>> extractEntityParameters = parameters.getParameters();
    final String contentAttribute = extractEntityParameters.get(ATTRIBUTE_PARAMETER_ID).getStringValue();
    final String words = extractEntityParameters.get(WORDS_PARAMETER_ID).getStringValue() == null ? null : extractEntityParameters.get(WORDS_PARAMETER_ID).getStringValue().trim();
    final boolean useRegex = extractEntityParameters.get(USE_REGEX_PARAMETER_ID).getBooleanValue();
    final boolean wholeWordOnly = extractEntityParameters.get(WHOLE_WORDS_ONLY_PARAMETER_ID).getBooleanValue();
    final int wordLength = parameters.getParameters().get(MIN_WORD_LENGTH_PARAMETER_ID).getIntegerValue();
    final boolean removeSpecialChars = extractEntityParameters.get(REMOVE_SPECIAL_CHARS_PARAMETER_ID).getBooleanValue();
    final boolean toLowerCase = extractEntityParameters.get(LOWER_CASE_PARAMETER_ID).getBooleanValue();
    final boolean types = extractEntityParameters.get(SCHEMA_TYPES_PARAMETER_ID).getBooleanValue();
    final String inOrOut = extractEntityParameters.get(IN_OR_OUT_PARAMETER_ID).getStringValue();
    final boolean selectedOnly = extractEntityParameters.get(SELECTED_ONLY_PARAMETER_ID).getBooleanValue();
    final boolean regexOnly = extractEntityParameters.get(REGEX_ONLY_PARAMETER_ID).getBooleanValue();
    if (!OUTGOING.equals(inOrOut) && !INCOMING.equals(inOrOut)) {
        var msg = String.format("Parameter %s must be '%s' or '%s'", REGEX_ONLY_PARAMETER_ID, OUTGOING, INCOMING);
        throw new PluginException(PluginNotificationLevel.ERROR, msg);
    }
    final boolean outgoing = OUTGOING.equals(inOrOut);
    /*
         Retrieving attribute IDs
         */
    final int vertexIdentifierAttributeId = VisualConcept.VertexAttribute.IDENTIFIER.ensure(wg);
    final int vertexTypeAttributeId = AnalyticConcept.VertexAttribute.TYPE.ensure(wg);
    final int transactionTypeAttributeId = AnalyticConcept.TransactionAttribute.TYPE.ensure(wg);
    final int transactionDatetimeAttributeId = TemporalConcept.TransactionAttribute.DATETIME.ensure(wg);
    final int transactionContentAttributeId = wg.getAttribute(GraphElementType.TRANSACTION, contentAttribute);
    final int transactionSelectedAttributeId = VisualConcept.TransactionAttribute.SELECTED.ensure(wg);
    // 
    if (transactionContentAttributeId == Graph.NOT_FOUND) {
        final NotifyDescriptor nd = new NotifyDescriptor.Message(String.format("The specified attribute %s does not exist.", contentAttribute), NotifyDescriptor.WARNING_MESSAGE);
        DialogDisplayer.getDefault().notify(nd);
        return;
    }
    final int transactionCount = wg.getTransactionCount();
    if (regexOnly) {
        // This choice ignores several other parameters, so is a bit simpler
        // even if there code commonalities, but combining the if/else
        // code would make things even more complex.
        // 
        // The input words are treated as trusted regular expressions,
        // so the caller has to know what they're doing.
        // This is power-use mode.
        // 
        // Each line of the input words is a regex.
        // Use them as-is for the power users.
        // 
        final List<Pattern> patterns = new ArrayList<>();
        if (StringUtils.isNotBlank(words)) {
            for (String word : words.split(SeparatorConstants.NEWLINE)) {
                word = word.strip();
                if (!word.isEmpty()) {
                    final Pattern pattern = Pattern.compile(word);
                    patterns.add(pattern);
                }
            }
        }
        if (!patterns.isEmpty()) {
            // Use a set to hold the words.
            // If a word is found multiple times, there's no point adding multiple nodes.
            // 
            final Set<String> matched = new HashSet<>();
            // 
            for (int transactionPosition = 0; transactionPosition < transactionCount; transactionPosition++) {
                final int transactionId = wg.getTransaction(transactionPosition);
                final boolean selectedTx = wg.getBooleanValue(transactionSelectedAttributeId, transactionId);
                if (selectedOnly && !selectedTx) {
                    continue;
                }
                final String content = wg.getStringValue(transactionContentAttributeId, transactionId);
                /*
                     Does the transaction have content?
                     */
                if (StringUtils.isBlank(content)) {
                    continue;
                }
                /*
                     Ignore other "referenced" transactions because that's not useful
                     */
                if (wg.getObjectValue(transactionTypeAttributeId, transactionId) != null && wg.getObjectValue(transactionTypeAttributeId, transactionId).equals(AnalyticConcept.TransactionType.REFERENCED)) {
                    continue;
                }
                patterns.stream().map(pattern -> pattern.matcher(content)).forEach(matcher -> {
                    while (matcher.find()) {
                        if (matcher.groupCount() == 0) {
                            // The regex doesn't have an explicit capture group, so capture the lot.
                            // 
                            final String g = matcher.group();
                            matched.add(toLowerCase ? g.toLowerCase() : g);
                        } else {
                            // 
                            for (int i = 1; i <= matcher.groupCount(); i++) {
                                final String g = matcher.group(i);
                                matched.add(toLowerCase ? g.toLowerCase() : g);
                            }
                        }
                    }
                });
                // 
                if (!matched.isEmpty()) {
                    /*
                         Retrieving information needed to create new transactions
                         */
                    final int sourceVertexId = wg.getTransactionSourceVertex(transactionId);
                    final int destinationVertexId = wg.getTransactionDestinationVertex(transactionId);
                    final ZonedDateTime datetime = wg.getObjectValue(transactionDatetimeAttributeId, transactionId);
                    matched.forEach(word -> {
                        final int newVertexId = wg.addVertex();
                        wg.setStringValue(vertexIdentifierAttributeId, newVertexId, word);
                        wg.setObjectValue(vertexTypeAttributeId, newVertexId, AnalyticConcept.VertexType.WORD);
                        final int newTransactionId = outgoing ? wg.addTransaction(sourceVertexId, newVertexId, true) : wg.addTransaction(newVertexId, destinationVertexId, true);
                        wg.setObjectValue(transactionDatetimeAttributeId, newTransactionId, datetime);
                        wg.setObjectValue(transactionTypeAttributeId, newTransactionId, AnalyticConcept.TransactionType.REFERENCED);
                        wg.setStringValue(transactionContentAttributeId, newTransactionId, content);
                    });
                }
            }
        }
    // End of regexOnly.
    } else {
        // The original logic.
        final List<Pattern> patterns = patternsFromWords(words, useRegex, wholeWordOnly);
        /*
             Iterating over all the transactions in the graph
             */
        final List<String> foundWords = new ArrayList<>();
        for (int transactionPosition = 0; transactionPosition < transactionCount; transactionPosition++) {
            foundWords.clear();
            final int transactionId = wg.getTransaction(transactionPosition);
            final boolean selectedTx = wg.getBooleanValue(transactionSelectedAttributeId, transactionId);
            if (selectedOnly && !selectedTx) {
                continue;
            }
            String content = wg.getStringValue(transactionContentAttributeId, transactionId);
            /*
                 Does the transaction have content?
                 */
            if (StringUtils.isBlank(content)) {
                continue;
            }
            /*
                 Ignore other "referenced" transactions because that's not useful
                 */
            if (wg.getObjectValue(transactionTypeAttributeId, transactionId) != null && wg.getObjectValue(transactionTypeAttributeId, transactionId).equals(AnalyticConcept.TransactionType.REFERENCED)) {
                continue;
            }
            /*
                 Retrieving information needed to create new transactions
                 */
            final int sourceVertexId = wg.getTransactionSourceVertex(transactionId);
            final int destinationVertexId = wg.getTransactionDestinationVertex(transactionId);
            final ZonedDateTime datetime = wg.getObjectValue(transactionDatetimeAttributeId, transactionId);
            final HashSet<String> typesExtracted = new HashSet<>();
            /*
                 Extracting Schema Types
                 */
            if (types) {
                final List<ExtractedVertexType> extractedTypes = SchemaVertexTypeUtilities.extractVertexTypes(content);
                final Map<String, SchemaVertexType> identifiers = new HashMap<>();
                extractedTypes.forEach(extractedType -> identifiers.put(extractedType.getIdentifier(), extractedType.getType()));
                for (String identifier : identifiers.keySet()) {
                    final int newVertexId = wg.addVertex();
                    wg.setStringValue(vertexIdentifierAttributeId, newVertexId, identifier);
                    wg.setObjectValue(vertexTypeAttributeId, newVertexId, identifiers.get(identifier));
                    final int newTransactionId = outgoing ? wg.addTransaction(sourceVertexId, newVertexId, true) : wg.addTransaction(newVertexId, destinationVertexId, true);
                    wg.setObjectValue(transactionDatetimeAttributeId, newTransactionId, datetime);
                    wg.setObjectValue(transactionTypeAttributeId, newTransactionId, AnalyticConcept.TransactionType.REFERENCED);
                    wg.setStringValue(transactionContentAttributeId, newTransactionId, content);
                    typesExtracted.add(identifier.toLowerCase());
                }
            }
            if (StringUtils.isBlank(words)) {
                /*
                     Extracting all words of the specified length if no word list has been provided
                     */
                for (String word : content.split(" ")) {
                    if (toLowerCase) {
                        word = word.toLowerCase();
                    }
                    if (removeSpecialChars) {
                        word = word.replaceAll("\\W", "");
                    }
                    if (word.length() < wordLength) {
                        continue;
                    }
                    foundWords.add(word);
                }
            } else {
                patterns.stream().map(pattern -> pattern.matcher(content)).forEach(matcher -> {
                    while (matcher.find()) {
                        final String g = matcher.group();
                        foundWords.add(toLowerCase ? g.toLowerCase() : g);
                    }
                });
            }
            /*
                 Add words to graph
                 */
            for (String word : foundWords) {
                if (types && typesExtracted.contains(word.toLowerCase())) {
                    continue;
                }
                final int newVertexId = wg.addVertex();
                wg.setStringValue(vertexIdentifierAttributeId, newVertexId, word);
                wg.setObjectValue(vertexTypeAttributeId, newVertexId, AnalyticConcept.VertexType.WORD);
                final int newTransactionId = outgoing ? wg.addTransaction(sourceVertexId, newVertexId, true) : wg.addTransaction(newVertexId, destinationVertexId, true);
                wg.setObjectValue(transactionDatetimeAttributeId, newTransactionId, datetime);
                wg.setObjectValue(transactionTypeAttributeId, newTransactionId, AnalyticConcept.TransactionType.REFERENCED);
                wg.setStringValue(transactionContentAttributeId, newTransactionId, content);
            }
        }
    }
    PluginExecutor.startWith(VisualSchemaPluginRegistry.COMPLETE_SCHEMA).followedBy(InteractiveGraphPluginRegistry.RESET_VIEW).executeNow(wg);
    interaction.setProgress(1, 0, "Completed successfully", true);
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) StringParameterType(au.gov.asd.tac.constellation.plugins.parameters.types.StringParameterType) SingleChoiceParameterType(au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType) ZonedDateTime(java.time.ZonedDateTime) StringAttributeDescription(au.gov.asd.tac.constellation.graph.attribute.StringAttributeDescription) PluginType(au.gov.asd.tac.constellation.plugins.PluginType) StringUtils(org.apache.commons.lang3.StringUtils) DataAccessPlugin(au.gov.asd.tac.constellation.views.dataaccess.plugins.DataAccessPlugin) Map(java.util.Map) PluginExecutor(au.gov.asd.tac.constellation.plugins.PluginExecutor) StringParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.StringParameterValue) InteractiveGraphPluginRegistry(au.gov.asd.tac.constellation.graph.interaction.InteractiveGraphPluginRegistry) SeparatorConstants(au.gov.asd.tac.constellation.utilities.text.SeparatorConstants) BooleanParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.BooleanParameterType.BooleanParameterValue) Set(java.util.Set) PluginNotificationLevel(au.gov.asd.tac.constellation.plugins.PluginNotificationLevel) PluginInfo(au.gov.asd.tac.constellation.plugins.PluginInfo) List(java.util.List) NotifyDescriptor(org.openide.NotifyDescriptor) IntegerParameterType(au.gov.asd.tac.constellation.plugins.parameters.types.IntegerParameterType) VisualSchemaPluginRegistry(au.gov.asd.tac.constellation.graph.schema.visual.VisualSchemaPluginRegistry) Pattern(java.util.regex.Pattern) Messages(org.openide.util.NbBundle.Messages) GraphWriteMethods(au.gov.asd.tac.constellation.graph.GraphWriteMethods) SchemaVertexTypeUtilities(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexTypeUtilities) IntegerParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.IntegerParameterType.IntegerParameterValue) ParameterChange(au.gov.asd.tac.constellation.plugins.parameters.ParameterChange) HashMap(java.util.HashMap) VisualConcept(au.gov.asd.tac.constellation.graph.schema.visual.concept.VisualConcept) ArrayList(java.util.ArrayList) Graph(au.gov.asd.tac.constellation.graph.Graph) HashSet(java.util.HashSet) Plugin(au.gov.asd.tac.constellation.plugins.Plugin) PluginInteraction(au.gov.asd.tac.constellation.plugins.PluginInteraction) ServiceProviders(org.openide.util.lookup.ServiceProviders) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) ServiceProvider(org.openide.util.lookup.ServiceProvider) PluginTags(au.gov.asd.tac.constellation.plugins.templates.PluginTags) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) ContentConcept(au.gov.asd.tac.constellation.graph.schema.analytic.concept.ContentConcept) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) DialogDisplayer(org.openide.DialogDisplayer) ExtractedVertexType(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexTypeUtilities.ExtractedVertexType) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) BooleanParameterType(au.gov.asd.tac.constellation.plugins.parameters.types.BooleanParameterType) SchemaVertexType(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType) AnalyticConcept(au.gov.asd.tac.constellation.graph.schema.analytic.concept.AnalyticConcept) TemporalConcept(au.gov.asd.tac.constellation.graph.schema.analytic.concept.TemporalConcept) SimpleQueryPlugin(au.gov.asd.tac.constellation.plugins.templates.SimpleQueryPlugin) DataAccessPluginCoreType(au.gov.asd.tac.constellation.views.dataaccess.plugins.DataAccessPluginCoreType) SingleChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType.SingleChoiceParameterValue) Pattern(java.util.regex.Pattern) SchemaVertexType(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType) HashMap(java.util.HashMap) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) ArrayList(java.util.ArrayList) ExtractedVertexType(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexTypeUtilities.ExtractedVertexType) NotifyDescriptor(org.openide.NotifyDescriptor) ZonedDateTime(java.time.ZonedDateTime) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) HashSet(java.util.HashSet)

Aggregations

SchemaVertexType (au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType)30 ArrayList (java.util.ArrayList)11 HashMap (java.util.HashMap)9 SchemaTransactionType (au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType)8 StoreGraph (au.gov.asd.tac.constellation.graph.StoreGraph)6 PluginParameter (au.gov.asd.tac.constellation.plugins.parameters.PluginParameter)6 Map (java.util.Map)6 SchemaConcept (au.gov.asd.tac.constellation.graph.schema.concept.SchemaConcept)5 SchemaVertexTypeUtilities (au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexTypeUtilities)5 List (java.util.List)5 Test (org.testng.annotations.Test)5 Graph (au.gov.asd.tac.constellation.graph.Graph)4 AnalyticConcept (au.gov.asd.tac.constellation.graph.schema.analytic.concept.AnalyticConcept)4 VisualConcept (au.gov.asd.tac.constellation.graph.schema.visual.concept.VisualConcept)4 MultiChoiceParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue)4 GraphWriteMethods (au.gov.asd.tac.constellation.graph.GraphWriteMethods)3 SchemaTransactionTypeUtilities (au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionTypeUtilities)3 PluginException (au.gov.asd.tac.constellation.plugins.PluginException)3 ParameterChange (au.gov.asd.tac.constellation.plugins.parameters.ParameterChange)3 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)3