Search in sources :

Example 26 with Document

use of com.ibm.cloud.cloudant.v1.model.Document in project inception by inception-project.

the class ExternalRecommender method buildDocument.

private Document buildDocument(CAS aCas) throws RecommendationException {
    CASMetadata casMetadata = getCasMetadata(aCas);
    String xmi = serializeCas(aCas);
    long documentId = casMetadata.getSourceDocumentId();
    String userId = casMetadata.getUsername();
    return new Document(xmi, documentId, userId);
}
Also used : CASMetadata(de.tudarmstadt.ukp.clarin.webanno.api.type.CASMetadata) Document(de.tudarmstadt.ukp.inception.recommendation.imls.external.v1.model.Document)

Example 27 with Document

use of com.ibm.cloud.cloudant.v1.model.Document in project inception by inception-project.

the class ExternalRecommender method train.

@Override
public void train(RecommenderContext aContext, List<CAS> aCasses) throws RecommendationException {
    TrainingRequest trainingRequest = new TrainingRequest();
    List<Document> documents = new ArrayList<>();
    // We assume that the type system for all CAS are the same
    String typeSystem = serializeTypeSystem(aCasses.get(0));
    trainingRequest.setTypeSystem(typeSystem);
    // Fill in metadata. We use the type system of the first CAS in the list
    // for all the other CAS. It could happen that training happens while
    // the type system changes, e.g. by adding a layer or feature during training.
    // Then the type system of the first CAS might not match the type system
    // of the other CAS. This should happen really rarely, therefore this potential
    // error is neglected.
    trainingRequest.setMetadata(buildMetadata(aCasses.get(0)));
    for (CAS cas : aCasses) {
        documents.add(buildDocument(cas));
    }
    trainingRequest.setDocuments(documents);
    HttpRequest request = // 
    HttpRequest.newBuilder().uri(// 
    URI.create(appendIfMissing(traits.getRemoteUrl(), "/")).resolve("train")).header(HttpHeaders.CONTENT_TYPE, // 
    APPLICATION_JSON_VALUE).timeout(properties.getReadTimeout()).POST(BodyPublishers.ofString(toJson(trainingRequest), UTF_8)).build();
    HttpResponse<String> response = sendRequest(request);
    if (response.statusCode() == HTTP_TOO_MANY_REQUESTS) {
        LOG.info("External recommender is already training");
    } else // then it does not make sense to go on and try to decode the XMI
    if (response.statusCode() >= HTTP_BAD_REQUEST) {
        String responseBody = getResponseBody(response);
        String msg = format("Request was not successful: [%d] - [%s]", response.statusCode(), responseBody);
        throw new RecommendationException(msg);
    }
    aContext.put(KEY_TRAINING_COMPLETE, true);
}
Also used : HttpRequest(java.net.http.HttpRequest) TrainingRequest(de.tudarmstadt.ukp.inception.recommendation.imls.external.v1.messages.TrainingRequest) CAS(org.apache.uima.cas.CAS) ArrayList(java.util.ArrayList) Document(de.tudarmstadt.ukp.inception.recommendation.imls.external.v1.model.Document) RecommendationException(de.tudarmstadt.ukp.inception.recommendation.api.recommender.RecommendationException)

Example 28 with Document

use of com.ibm.cloud.cloudant.v1.model.Document in project knative-eventing-java-app by IBM.

the class CloudEventStoreCloudant method addEvent.

@Override
public void addEvent(CloudEvent<?, ?> event) throws Exception {
    // Convert event into document object
    Document document = new Document();
    // https://github.com/cloudant/java-cloudant/blob/master/MIGRATION.md
    document.setProperties(this.gson.fromJson(this.gson.toJson(event), Map.class));
    // Post document and get response
    PostDocumentOptions postDocumentOptions = new PostDocumentOptions.Builder().db(this.dbName).document(document).build();
    DocumentResult response = this.client.postDocument(postDocumentOptions).execute().getResult();
    // Check for errors
    String error = response.getError();
    if (error != null) {
        logger.error("Error adding event to Cloudant: " + error);
        throw new Exception(error);
    }
}
Also used : DocumentResult(com.ibm.cloud.cloudant.v1.model.DocumentResult) Document(com.ibm.cloud.cloudant.v1.model.Document) Map(java.util.Map) PostDocumentOptions(com.ibm.cloud.cloudant.v1.model.PostDocumentOptions) NotFoundException(com.ibm.cloud.sdk.core.service.exception.NotFoundException)

Example 29 with Document

use of com.ibm.cloud.cloudant.v1.model.Document in project dna by leifeld.

the class DocumentEditor method createGui.

private void createGui(int numDocuments) {
    String toolTipText = "<html><p width=\"500\">Overwrite the document contents and meta-data " + "by editing the fields shown in this editor dialog.</p>" + "<p width=\"500\">Note that the document text field is only editable if there are " + "no statements contained in the document.</p>" + "<p width=\"500\">In the title, author, source, section, type, notes, and text " + "fields, the following wildcards can be used (across the different fields) to " + "represent the contents of the respective field that are currently saved " + "in the database:</p>" + "<dl>" + "<dt><b>%title</b></dt><dd>Represents the current contents of the title field.</dd>" + "<dt><b>%author</b></dt><dd>Represents the current contents of the author field.</dd>" + "<dt><b>%source</b></dt><dd>Represents the current contents of the source field.</dd>" + "<dt><b>%section</b></dt><dd>Represents the current contents of the section field.</dd>" + "<dt><b>%type</b></dt><dd>Represents the current contents of the type field.</dd>" + "<dt><b>%notes</b></dt><dd>Represents the current contents of the notes field.</dd>" + "<dt><b>%text</b></dt><dd>Represents the current contents of the text field.</dd>" + "<dt><b>%day</b></dt><dd>Represents the current day (1-31) of the document.</dd>" + "<dt><b>%month</b></dt><dd>Represents the current month (1-12) of the document.</dd>" + "<dt><b>%year</b></dt><dd>Represents the current year (e.g., 2007) of the document.</dd>" + "<dt><b>%hour</b></dt><dd>Represents the current hour (0-23) of the document.</dd>" + "<dt><b>%minute</b></dt><dd>Represents the current minute (0-59) of the document.</dd>" + "</dl>" + "<p width=\"500\">For example, you can combine title and date like this: " + "%title (%day.%month.%year).</p>" + "<p width=\"500\">Note that the date or time fields may show as empty when multiple " + "documents are edited simultaneously. This just means the original date or time will be " + "kept when saving unless edited. It is possible to edit only the date or only the time " + "if necessary while keeping the other field empty.</p></html>";
    this.setModal(true);
    if (numDocuments == 0) {
        this.setTitle("Add new document...");
    } else {
        String s = " document...";
        if (numDocuments > 1) {
            s = " documents...";
        }
        this.setTitle("Edit " + numDocuments + s);
    }
    this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    ImageIcon tableAddIcon = new ImageIcon(getClass().getResource("/icons/tabler-icon-file-plus.png"));
    this.setIconImage(tableAddIcon.getImage());
    this.setLayout(new FlowLayout(FlowLayout.LEFT));
    textArea = new JXTextArea("paste the contents of the document here using Ctrl-V...");
    textArea.setLineWrap(true);
    textArea.setWrapStyleWord(true);
    textScroller = new JScrollPane(textArea);
    textScroller.setPreferredSize(new Dimension(700, 360));
    textScroller.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    textScroller.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    if (numDocuments > 0) {
        textScroller.setToolTipText(toolTipText);
    }
    JPanel fieldsPanel = new JPanel(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.HORIZONTAL;
    // first column: labels
    gbc.insets = new Insets(3, 0, 3, 7);
    gbc.gridy = 0;
    gbc.gridx = 0;
    JLabel titleLabel = new JLabel("title", JLabel.RIGHT);
    if (numDocuments > 0) {
        titleLabel.setToolTipText(toolTipText);
    }
    fieldsPanel.add(titleLabel, gbc);
    gbc.gridy = 1;
    gbc.gridx = 0;
    JLabel dateLabel = new JLabel("date", JLabel.RIGHT);
    if (numDocuments > 0) {
        dateLabel.setToolTipText(toolTipText);
    }
    fieldsPanel.add(dateLabel, gbc);
    gbc.gridy = 2;
    gbc.gridx = 0;
    JLabel coderLabel = new JLabel("coder", JLabel.RIGHT);
    fieldsPanel.add(coderLabel, gbc);
    gbc.gridy = 3;
    gbc.gridx = 0;
    JLabel authorLabel = new JLabel("author", JLabel.RIGHT);
    if (numDocuments > 0) {
        authorLabel.setToolTipText(toolTipText);
    }
    fieldsPanel.add(authorLabel, gbc);
    gbc.gridy = 4;
    gbc.gridx = 0;
    JLabel sourceLabel = new JLabel("source", JLabel.RIGHT);
    if (numDocuments > 0) {
        sourceLabel.setToolTipText(toolTipText);
    }
    fieldsPanel.add(sourceLabel, gbc);
    gbc.gridy = 5;
    gbc.gridx = 0;
    JLabel sectionLabel = new JLabel("section", JLabel.RIGHT);
    if (numDocuments > 0) {
        sectionLabel.setToolTipText(toolTipText);
    }
    fieldsPanel.add(sectionLabel, gbc);
    gbc.gridy = 6;
    gbc.gridx = 0;
    JLabel typeLabel = new JLabel("type", JLabel.RIGHT);
    if (numDocuments > 0) {
        typeLabel.setToolTipText(toolTipText);
    }
    fieldsPanel.add(typeLabel, gbc);
    gbc.gridy = 7;
    gbc.gridx = 0;
    gbc.anchor = GridBagConstraints.NORTH;
    JLabel notesLabel = new JLabel("notes", JLabel.RIGHT);
    if (numDocuments > 0) {
        notesLabel.setToolTipText(toolTipText);
    }
    fieldsPanel.add(notesLabel, gbc);
    gbc.gridy = 8;
    gbc.gridx = 0;
    JLabel textLabel = new JLabel("text", JLabel.RIGHT);
    if (numDocuments > 0) {
        textLabel.setToolTipText(toolTipText);
    }
    fieldsPanel.add(textLabel, gbc);
    // second column: fields
    gbc.insets = new Insets(3, 0, 3, 0);
    gbc.gridy = 0;
    gbc.gridx = 1;
    gbc.gridwidth = 3;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.weightx = 1.0;
    titleField = new JXTextField("paste the title of the document here using Ctrl-V...");
    titleField.setColumns(60);
    if (numDocuments > 0) {
        titleField.setToolTipText(toolTipText);
    }
    fieldsPanel.add(titleField, gbc);
    if (numDocuments < 2) {
        titleField.getDocument().addDocumentListener(new DocumentListener() {

            @Override
            public void changedUpdate(DocumentEvent e) {
                checkButton();
            }

            @Override
            public void insertUpdate(DocumentEvent e) {
                checkButton();
            }

            @Override
            public void removeUpdate(DocumentEvent e) {
                checkButton();
            }

            public void checkButton() {
                boolean problem = false;
                if (titleField.getText().equals("")) {
                    problem = true;
                }
                if (problem == true) {
                    okButton.setEnabled(false);
                } else {
                    okButton.setEnabled(true);
                }
            }
        });
    }
    gbc.gridy = 1;
    gbc.gridx = 1;
    gbc.fill = GridBagConstraints.NONE;
    gbc.anchor = GridBagConstraints.WEST;
    DatePickerSettings dateSettings = new DatePickerSettings();
    dateSettings.setFormatForDatesCommonEra("dd MM yyyy");
    dateSettings.setFormatForDatesBeforeCommonEra("dd MM uuuu");
    TimePickerSettings timeSettings = new TimePickerSettings();
    timeSettings.setFormatForDisplayTime("HH:mm:ss");
    timeSettings.setFormatForMenuTimes("HH:mm:ss");
    dateTimePicker = new DateTimePicker(dateSettings, timeSettings);
    dateTimePicker.getDatePicker().setDateToToday();
    dateTimePicker.getTimePicker().setTime(LocalTime.MIDNIGHT);
    ImageIcon dateIcon = new ImageIcon(new ImageIcon(getClass().getResource("/icons/tabler-icon-calendar-event.png")).getImage().getScaledInstance(16, 16, Image.SCALE_SMOOTH));
    JButton dateButton = dateTimePicker.getDatePicker().getComponentToggleCalendarButton();
    dateButton.setText("");
    dateButton.setIcon(dateIcon);
    ImageIcon timeIcon = new ImageIcon(new ImageIcon(getClass().getResource("/icons/tabler-icon-clock.png")).getImage().getScaledInstance(16, 16, Image.SCALE_SMOOTH));
    JButton timeButton = dateTimePicker.getTimePicker().getComponentToggleTimeMenuButton();
    timeButton.setText("");
    timeButton.setIcon(timeIcon);
    if (numDocuments > 0) {
        dateTimePicker.setToolTipText(toolTipText);
        dateButton.setToolTipText(toolTipText);
        timeButton.setToolTipText(toolTipText);
    }
    fieldsPanel.add(dateTimePicker, gbc);
    gbc.gridy = 2;
    gbc.gridx = 1;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    if (Dna.sql.getActiveCoder().isPermissionEditOthersDocuments()) {
        // create list of eligible coders
        List<Coder> eligibleCoders = Dna.sql.getCoders().stream().filter(e -> e.getId() == Dna.sql.getActiveCoder().getId() || (e.getId() != Dna.sql.getActiveCoder().getId() && Dna.sql.getActiveCoder().isPermissionEditOthersDocuments(e.getId()))).sorted().collect(Collectors.toList());
        if (eligibleCoders.size() == 1) {
            // only one eligible coder (must be the active coder); create coder badge panel instead of combo box
            this.cbp = new CoderBadgePanel(eligibleCoders.get(0));
            fieldsPanel.add(this.cbp, gbc);
        } else {
            // check if there is only a single coder across the documents and add a fake coder for multiple coders coder varies across documents
            boolean oneCoder = (numDocuments == 0 || documents.stream().mapToInt(Document::getCoder).distinct().limit(2).count() <= 1);
            if (!oneCoder) {
                eligibleCoders.add(0, new Coder(-1, "(keep multiple coders)", Color.BLACK));
            }
            // create and populate combo box with coders
            ArrayList<Coder> coderArrayList = new ArrayList<Coder>(eligibleCoders);
            this.coderComboBox = new JComboBox<Coder>();
            CoderComboBoxModel comboBoxModel = new CoderComboBoxModel(coderArrayList);
            this.coderComboBox.setModel(comboBoxModel);
            this.coderComboBox.setRenderer(new CoderComboBoxRenderer(18, 0, 97));
            // select the right coder and add combo box to panel
            if (numDocuments == 0) {
                this.coderComboBox.setSelectedIndex(IntStream.range(0, eligibleCoders.size()).filter(i -> Dna.sql.getActiveCoder().getId() == eligibleCoders.get(i).getId()).findFirst().getAsInt());
            } else if (oneCoder) {
                this.coderComboBox.setSelectedIndex(IntStream.range(0, eligibleCoders.size()).filter(i -> documents.get(0).getCoder() == eligibleCoders.get(i).getId()).findFirst().getAsInt());
            } else {
                this.coderComboBox.setSelectedIndex(0);
            }
            fieldsPanel.add(this.coderComboBox, gbc);
        }
    } else {
        // no permission to add other coders' documents; create coder badge panel
        this.cbp = new CoderBadgePanel(Dna.sql.getActiveCoder());
        fieldsPanel.add(this.cbp, gbc);
    }
    gbc.gridy = 3;
    gbc.gridx = 1;
    authorBox = new JXComboBox();
    authorBox.setEditable(true);
    AutoCompleteDecorator.decorate(authorBox);
    if (numDocuments > 0) {
        authorBox.setToolTipText(toolTipText);
    }
    authorBox.setRenderer(new ComboBoxRenderer());
    fieldsPanel.add(authorBox, gbc);
    gbc.gridy = 4;
    gbc.gridx = 1;
    sourceBox = new JXComboBox();
    sourceBox.setEditable(true);
    sourceBox.setSelectedItem("");
    AutoCompleteDecorator.decorate(sourceBox);
    if (numDocuments > 0) {
        sourceBox.setToolTipText(toolTipText);
    }
    sourceBox.setRenderer(new ComboBoxRenderer());
    fieldsPanel.add(sourceBox, gbc);
    gbc.gridy = 5;
    gbc.gridx = 1;
    sectionBox = new JXComboBox();
    sectionBox.setEditable(true);
    sectionBox.setSelectedItem("");
    AutoCompleteDecorator.decorate(sectionBox);
    if (numDocuments > 0) {
        sectionBox.setToolTipText(toolTipText);
    }
    sectionBox.setRenderer(new ComboBoxRenderer());
    fieldsPanel.add(sectionBox, gbc);
    gbc.gridy = 6;
    gbc.gridx = 1;
    typeBox = new JXComboBox();
    typeBox.setEditable(true);
    typeBox.setSelectedItem("");
    AutoCompleteDecorator.decorate(typeBox);
    if (numDocuments > 0) {
        typeBox.setToolTipText(toolTipText);
    }
    typeBox.setRenderer(new ComboBoxRenderer());
    JDBCWorker worker = new JDBCWorker(numDocuments == 0);
    worker.execute();
    fieldsPanel.add(typeBox, gbc);
    gbc.gridy = 7;
    gbc.gridx = 1;
    notesArea = new JXTextArea("notes...");
    notesArea.setLineWrap(true);
    notesArea.setWrapStyleWord(true);
    notesArea.setRows(4);
    JScrollPane notesScroller = new JScrollPane(notesArea);
    notesScroller.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    if (numDocuments > 0) {
        notesScroller.setToolTipText(toolTipText);
    }
    fieldsPanel.add(notesScroller, gbc);
    gbc.gridy = 8;
    gbc.gridx = 1;
    fieldsPanel.add(textScroller, gbc);
    newArticlePanel = new JPanel(new BorderLayout());
    newArticlePanel.add(fieldsPanel, BorderLayout.CENTER);
    FlowLayout fl = new FlowLayout(FlowLayout.RIGHT);
    JPanel buttons = new JPanel(fl);
    ImageIcon cancelIcon = new ImageIcon(new ImageIcon(getClass().getResource("/icons/tabler-icon-x.png")).getImage().getScaledInstance(18, 18, Image.SCALE_SMOOTH));
    JButton cancelButton = new JButton("Cancel", cancelIcon);
    cancelButton.setToolTipText("close this window without making any changes");
    cancelButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            dispose();
        }
    });
    buttons.add(cancelButton);
    ImageIcon okIcon = new ImageIcon(new ImageIcon(getClass().getResource("/icons/tabler-icon-check.png")).getImage().getScaledInstance(18, 18, Image.SCALE_SMOOTH));
    String okString = "Add";
    if (numDocuments > 0) {
        okString = "Update";
    }
    okButton = new JButton(okString, okIcon);
    if (numDocuments == 0) {
        okButton.setToolTipText("insert a new article based on the information you entered in this window");
        okButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                int coder = 1;
                if (DocumentEditor.this.cbp != null) {
                    coder = cbp.getCoder().getId();
                } else {
                    coder = ((Coder) coderComboBox.getSelectedItem()).getId();
                }
                String text = textArea.getText();
                String title = titleField.getText().substring(0, Math.min(190, titleField.getText().length()));
                LocalDateTime dateTime = dateTimePicker.getDateTimeStrict();
                String author = ((String) authorBox.getModel().getSelectedItem()).substring(0, Math.min(190, ((String) authorBox.getModel().getSelectedItem()).length()));
                String source = ((String) sourceBox.getModel().getSelectedItem()).substring(0, Math.min(190, ((String) sourceBox.getModel().getSelectedItem()).length()));
                String section = ((String) sectionBox.getModel().getSelectedItem()).substring(0, Math.min(190, ((String) sectionBox.getModel().getSelectedItem()).length()));
                String notes = notesArea.getText();
                String type = ((String) typeBox.getModel().getSelectedItem()).substring(0, Math.min(190, ((String) typeBox.getModel().getSelectedItem()).length()));
                ArrayList<Document> al = new ArrayList<Document>();
                Document d = new Document(-1, coder, title, text, author, source, section, type, notes, dateTime, new ArrayList<Statement>());
                al.add(d);
                documents = al;
                documentIds = Dna.sql.addDocuments(documents);
                changesApplied = true;
                LogEvent l = new LogEvent(Logger.MESSAGE, "[GUI] A new document was added to the database.", "A new document was manually added to the database by clicking on the Add button in a New Document dialog window.");
                Dna.logger.log(l);
                dispose();
            }
        });
        okButton.setEnabled(false);
    } else {
        okButton.setToolTipText("save updated document data into the database");
        okButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                int coder = 1;
                if (DocumentEditor.this.cbp != null) {
                    coder = cbp.getCoder().getId();
                } else {
                    // can be -1 for keeping existing coders; needs to be taken care of in the Sql.updateDocuments method
                    coder = ((Coder) coderComboBox.getSelectedItem()).getId();
                }
                String message = "Are you sure you want to recode " + documentIds.length + " documents and save the changes to the database?";
                int dialog = JOptionPane.showConfirmDialog(DocumentEditor.this, message, "Confirmation required", JOptionPane.YES_NO_OPTION);
                if (dialog == 0) {
                    LocalDate ld = dateTimePicker.getDatePicker().getDate();
                    LocalTime lt = dateTimePicker.getTimePicker().getTime();
                    Dna.sql.updateDocuments(documentIds, coder, titleField.getText(), textArea.getText(), (String) authorBox.getSelectedItem(), (String) sourceBox.getSelectedItem(), (String) sectionBox.getSelectedItem(), (String) typeBox.getSelectedItem(), notesArea.getText(), ld, lt);
                    changesApplied = true;
                    LogEvent l = new LogEvent(Logger.MESSAGE, "[GUI] " + documentIds.length + " documents were updated in the database.", "Using a Document Editor dialog window, the meta-data of " + documentIds.length + " documents were updated in the database.");
                    Dna.logger.log(l);
                }
                dispose();
            }
        });
    }
    buttons.add(okButton);
    newArticlePanel.add(buttons, BorderLayout.SOUTH);
    // add contents for editing if this is not a new document
    if (numDocuments > 0) {
        String contentTitle = documents.get(0).getTitle();
        titleField.setText(contentTitle);
        if (numDocuments > 1) {
            for (int i = 0; i < documents.size(); i++) {
                if (!documents.get(i).getTitle().equals(contentTitle)) {
                    titleField.setText("%title");
                    titleField.setPrompt("(Overwrite all titles at once by replacing this text.)");
                    break;
                }
            }
        }
        String contentText = documents.get(0).getText();
        if (Dna.sql.documentsContainStatements(documentIds) == true) {
            textArea.setEditable(false);
        }
        if (numDocuments > 1) {
            for (int i = 0; i < documents.size(); i++) {
                if (!documents.get(i).getText().equals(contentText)) {
                    textArea.setText("%text");
                    textArea.setPrompt("(Overwrite all texts at once by replacing this text.)");
                    break;
                }
            }
        }
        if (textArea.getText().equals("")) {
            textArea.setText(contentText);
        }
        String contentNotes = documents.get(0).getNotes();
        notesArea.setText(contentNotes);
        if (numDocuments > 1) {
            for (int i = 0; i < documents.size(); i++) {
                if (!documents.get(i).getNotes().equals(contentNotes)) {
                    notesArea.setText("%notes");
                    notesArea.setPrompt("(Overwrite all notes at once by replacing this text.)");
                    break;
                }
            }
        }
        String contentAuthor = documents.get(0).getAuthor();
        authorBox.setSelectedItem(contentAuthor);
        if (numDocuments > 1) {
            for (int i = 0; i < documents.size(); i++) {
                if (!documents.get(i).getAuthor().equals(contentAuthor)) {
                    authorBox.setSelectedItem("%author");
                    break;
                }
            }
        }
        String contentSource = documents.get(0).getSource();
        sourceBox.setSelectedItem(contentSource);
        if (numDocuments > 1) {
            for (int i = 0; i < documents.size(); i++) {
                if (!documents.get(i).getSource().equals(contentSource)) {
                    sourceBox.setSelectedItem("%source");
                    break;
                }
            }
        }
        String contentSection = documents.get(0).getSection();
        sectionBox.setSelectedItem(contentSection);
        if (numDocuments > 1) {
            for (int i = 0; i < documents.size(); i++) {
                if (!documents.get(i).getSection().equals(contentSection)) {
                    sectionBox.setSelectedItem("%section");
                    break;
                }
            }
        }
        String contentType = documents.get(0).getType();
        typeBox.setSelectedItem(contentType);
        if (numDocuments > 1) {
            for (int i = 0; i < documents.size(); i++) {
                if (!documents.get(i).getType().equals(contentType)) {
                    typeBox.setSelectedItem("%type");
                    break;
                }
            }
        }
        LocalDateTime contentDateTime = documents.get(0).getDateTime();
        dateTimePicker.setDateTimeStrict(contentDateTime);
        if (numDocuments > 1) {
            for (int i = 0; i < documents.size(); i++) {
                if (!documents.get(i).getDateTime().equals(contentDateTime)) {
                    dateTimePicker.clear();
                    break;
                }
            }
        }
    }
    this.add(newArticlePanel);
    this.pack();
    this.setLocationRelativeTo(null);
    this.setVisible(true);
}
Also used : Color(java.awt.Color) UIManager(javax.swing.UIManager) Connection(java.sql.Connection) DocumentListener(javax.swing.event.DocumentListener) JDialog(javax.swing.JDialog) ResultSet(java.sql.ResultSet) LocalTime(java.time.LocalTime) SwingWorker(javax.swing.SwingWorker) BorderLayout(java.awt.BorderLayout) JComboBox(javax.swing.JComboBox) JFrame(javax.swing.JFrame) DateTimePicker(com.github.lgooddatepicker.components.DateTimePicker) Image(java.awt.Image) GridBagConstraints(java.awt.GridBagConstraints) PreparedStatement(java.sql.PreparedStatement) Component(java.awt.Component) Collectors(java.util.stream.Collectors) Dna(dna.Dna) Logger(logger.Logger) Dimension(java.awt.Dimension) List(java.util.List) LocalDate(java.time.LocalDate) GridBagLayout(java.awt.GridBagLayout) Document(model.Document) JPanel(javax.swing.JPanel) DatePickerSettings(com.github.lgooddatepicker.components.DatePickerSettings) IntStream(java.util.stream.IntStream) Insets(java.awt.Insets) AutoCompleteDecorator(org.jdesktop.swingx.autocomplete.AutoCompleteDecorator) ActionListener(java.awt.event.ActionListener) LocalDateTime(java.time.LocalDateTime) Coder(model.Coder) ArrayList(java.util.ArrayList) JXTextField(org.jdesktop.swingx.JXTextField) SQLException(java.sql.SQLException) ImageIcon(javax.swing.ImageIcon) JXComboBox(org.jdesktop.swingx.JXComboBox) DocumentEvent(javax.swing.event.DocumentEvent) FlowLayout(java.awt.FlowLayout) JButton(javax.swing.JButton) JList(javax.swing.JList) JOptionPane(javax.swing.JOptionPane) ActionEvent(java.awt.event.ActionEvent) LogEvent(logger.LogEvent) JScrollPane(javax.swing.JScrollPane) TimePickerSettings(com.github.lgooddatepicker.components.TimePickerSettings) ListCellRenderer(javax.swing.ListCellRenderer) JLabel(javax.swing.JLabel) JXTextArea(org.jdesktop.swingx.JXTextArea) Statement(model.Statement) LocalDateTime(java.time.LocalDateTime) ImageIcon(javax.swing.ImageIcon) JPanel(javax.swing.JPanel) DocumentListener(javax.swing.event.DocumentListener) GridBagConstraints(java.awt.GridBagConstraints) FlowLayout(java.awt.FlowLayout) Insets(java.awt.Insets) TimePickerSettings(com.github.lgooddatepicker.components.TimePickerSettings) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) JXTextArea(org.jdesktop.swingx.JXTextArea) JButton(javax.swing.JButton) ArrayList(java.util.ArrayList) DateTimePicker(com.github.lgooddatepicker.components.DateTimePicker) Document(model.Document) LocalDate(java.time.LocalDate) JXTextField(org.jdesktop.swingx.JXTextField) DatePickerSettings(com.github.lgooddatepicker.components.DatePickerSettings) BorderLayout(java.awt.BorderLayout) JXComboBox(org.jdesktop.swingx.JXComboBox) JScrollPane(javax.swing.JScrollPane) Coder(model.Coder) LocalTime(java.time.LocalTime) LogEvent(logger.LogEvent) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) DocumentEvent(javax.swing.event.DocumentEvent) ActionListener(java.awt.event.ActionListener)

Example 30 with Document

use of com.ibm.cloud.cloudant.v1.model.Document in project inception by inception-project.

the class ExternalRecommenderIntegrationTest method thatTrainingSendsCorrectRequest.

@Test
public void thatTrainingSendsCorrectRequest() throws Exception {
    List<CAS> casses = loadDevelopmentData();
    sut.train(context, casses);
    TrainingRequest request = fromJsonString(TrainingRequest.class, requestBodies.get(0));
    // 
    assertThat(request.getMetadata()).hasNoNullFieldsOrProperties().hasFieldOrPropertyWithValue("projectId", PROJECT_ID).hasFieldOrPropertyWithValue("layer", recommender.getLayer().getName()).hasFieldOrPropertyWithValue("feature", recommender.getFeature().getName()).hasFieldOrPropertyWithValue("crossSentence", CROSS_SENTENCE).hasFieldOrPropertyWithValue("anchoringMode", ANCHORING_MODE.getId());
    for (int i = 0; i < request.getDocuments().size(); i++) {
        Document doc = request.getDocuments().get(i);
        assertThat(doc).hasFieldOrPropertyWithValue("documentId", (long) i).hasFieldOrPropertyWithValue("userId", USER_NAME);
    }
}
Also used : CAS(org.apache.uima.cas.CAS) TrainingRequest(de.tudarmstadt.ukp.inception.recommendation.imls.external.v1.messages.TrainingRequest) Document(de.tudarmstadt.ukp.inception.recommendation.imls.external.v1.model.Document) Test(org.junit.jupiter.api.Test)

Aggregations

HashMap (java.util.HashMap)32 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)30 Document (com.ibm.cloud.cloudant.v1.model.Document)22 DocumentResult (com.ibm.cloud.cloudant.v1.model.DocumentResult)20 ArrayList (java.util.ArrayList)16 Test (org.testng.annotations.Test)12 Attachment (com.ibm.cloud.cloudant.v1.model.Attachment)10 DocumentRevisionStatus (com.ibm.cloud.cloudant.v1.model.DocumentRevisionStatus)10 Revisions (com.ibm.cloud.cloudant.v1.model.Revisions)10 DesignDocument (com.ibm.cloud.cloudant.v1.model.DesignDocument)9 ReplicationDocument (com.ibm.cloud.cloudant.v1.model.ReplicationDocument)9 SchedulerDocument (com.ibm.cloud.cloudant.v1.model.SchedulerDocument)9 JsonObject (com.google.gson.JsonObject)8 AllDocsResult (com.ibm.cloud.cloudant.v1.model.AllDocsResult)6 BulkGetQueryDocument (com.ibm.cloud.cloudant.v1.model.BulkGetQueryDocument)6 BulkGetResultDocument (com.ibm.cloud.cloudant.v1.model.BulkGetResultDocument)6 MockResponse (okhttp3.mockwebserver.MockResponse)6 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 PostDocumentOptions (com.ibm.cloud.cloudant.v1.model.PostDocumentOptions)5