我是一名自学成才的程序员,目前正在从事工作清单网站项目。我有一个带有搜索功能的工作清单页面。现在,用户可以按职位搜索,并且我想添加按关键字搜索的选项。
HTML
每个作业都有6个属性:作业标题,作业位置,作业类型,作业行业和作业关键字。作业关键字是一个列表,因为作业可以具有不同数量的关键字。
cat first.csv second.csv > final.csv
join -t, first.csv second.csv > final.csv
按标题搜索的JS:
<div class="job-listing">
<div class="container">
<div class="job-number">
<h2>We Found <span id="number-jobs-total" class="text-secondary">214</span> Offers For <span>You</span> </h2>
</div>
<ul class="job-board">
<li class="job job-1">
<div class="job-title">
<h2>Process Engineer</h2>
</div>
<div class="job-location">
<p>Location: Naypyitaw</p>
</div>
<div class="job-type">
<p>Type: Full-Time</p>
</div>
<div class="job-date">
<p>Published on 07/19/2019</p>
</div>
<div class="job-industry">
<p>Engineering</p>
</div>
<ul class="job-keywords">
<li>Engineering</li>
<li>Science</li>
</ul>
</li>
<li class="job job-2">
<div class="job-title">
<h2>Chief Financial Officier</h2>
</div>
<div class="job-location">
<p>Location: Naypyitaw</p>
</div>
<div class="job-type">
<p>Type: Full-Time</p>
</div>
<div class="job-date">
<p>Published on 07/18/2019</p>
</div>
</li>
<li class="job job-3">
<div class="job-title">
<h2>Assistant CEO</h2>
</div>
<div class="job-location">
<p>Location: Naypyitaw</p>
</div>
<div class="job-type">
<p>Type: Part-Time</p>
</div>
<div class="job-date">
<p>Published on 07/18/2019</p>
</div>
</li>
<li class="job job-4">
<div class="job-title">
<h2>Front-End Developer</h2>
</div>
<div class="job-location">
<p>Location: Naypyitaw</p>
</div>
<div class="job-type">
<p>Type: Part-Time</p>
</div>
<div class="job-date">
<p>Published on 07/18/2019</p>
</div>
</li>
</ul>
<nav class="pagination-container">
<ul class="pagination">
<li><a href="javascript:void(0)">Previous</a></li>
<li><a href="javascript:void(0)">Next</a></li>
</ul>
</nav>
</div>
</div>
JS:我已经尝试过了,虽然我不算很远,但是仍然无法正常工作
const search= document.querySelector(".skills");
const jobs = Array.from(document.querySelector(".job-board").children);
const filterJobs = term => {
jobs.filter(job =>{
const title = job.querySelector(".job-title").textContent.toLowerCase();
if(title.includes(term.toLowerCase()) || totalKeywords.includes(term.toLowerCase()) ){
job.style.display = "list-item";
} else{
job.style.display = "none";
}
});
};
search.addEventListener("keyup", e =>{
filterJobs(e.currentTarget.value.trim());
});
答案 0 :(得分:3)
我认为您的代码存在问题,因为关键字不是字符串而是字符串数组,因此您需要在关键字数组即
中进行搜索 let inKeywords = totalKeywords.some(keyword => keyword.toLowerCase().includes(term.toLowerCase()));
if(title.includes(term.toLowerCase()) || inKeywords ){
job.style.display = "list-item";
} else{
job.style.display = "none";
}
答案 1 :(得分:0)
我建议您不要使用from torch import nn
import torch
import tensorflow as tf
import math
time_step = 50 # Input sequence length
vocab_size = 20 # Number of classes
batch_size = 16 # Batch size
target_sequence_length = 30 # Target sequence length
def dense_to_sparse(dense_tensor, sequence_length):
indices = tf.where(tf.sequence_mask(sequence_length))
values = tf.gather_nd(dense_tensor, indices)
shape = tf.shape(dense_tensor, out_type=tf.int64)
return tf.SparseTensor(indices, values, shape)
def compute_loss(x, y, x_len):
ctclosses = tf.nn.ctc_loss(
y,
tf.cast(x, dtype=tf.float32),
x_len,
preprocess_collapse_repeated=False,
ctc_merge_repeated=False,
ignore_longer_outputs_than_inputs=False
)
ctclosses = tf.reduce_mean(ctclosses)
with tf.Session() as sess:
ctclosses = sess.run(ctclosses)
print(f"tf ctc loss: {ctclosses}")
print(f"tf log(ctc loss): {math.log(ctclosses)}")
minimum_target_length = 10
ctc_loss = nn.CTCLoss(blank=vocab_size - 1)
x = torch.randn(time_step, batch_size, vocab_size) # [size] = T,N,C
y = torch.randint(0, vocab_size - 2, (batch_size, target_sequence_length), dtype=torch.long) # low, high, [size]
x_lengths = torch.full((batch_size,), time_step, dtype=torch.long) # Length of inputs
y_lengths = torch.randint(minimum_target_length, target_sequence_length, (batch_size,),
dtype=torch.long) # Length of targets can be variable (even if target sequences are constant length)
loss = ctc_loss(x.log_softmax(2).detach(), y, x_lengths, y_lengths)
print(f"torch ctc loss: {loss}")
x = x.numpy()
y = y.numpy()
x_lengths = x_lengths.numpy()
y_lengths = y_lengths.numpy()
x = tf.cast(x, dtype=tf.float32)
y = tf.cast(dense_to_sparse(y, y_lengths), dtype=tf.int32)
compute_loss(x, y, x_lengths)
,而建议使用tf.nn.ctc_loss
。您可以找到更多信息here
pytorch.nn.CTCLoss
答案 2 :(得分:0)
这是这种前端过滤的好技巧。我不知道这是否是您想要的东西,因为这并不是OP的要求,但这会在您的所有字段(标题,位置,类型,日期,行业,关键字)中进行搜索:
const search= document.querySelector(".skills");
const jobs = Array.from(document.querySelector(".job-board").children);
const filterJobs = term => {
jobs.filter(job =>{
jobText = job.textContent || job.innerText || ""; // strip html tags from the job element and keeps only text
jobText = jobText.toLowerCase();
if(jobText.indexOf(term.toLowerCase()) > -1){
job.style.display = "list-item";
}
else{
job.style.display = "none";
}
});
};
search.addEventListener("keyup", e =>{
filterJobs(e.currentTarget.value.trim());
});
<input type="text" class="skills" placeholder="search">
<div class="job-listing">
<div class="container">
<div class="job-number">
<h2>We Found <span id="number-jobs-total" class="text-secondary">214</span> Offers For <span>You</span> </h2>
</div>
<ul class="job-board">
<li class="job job-1">
<div class="job-title">
<h2>Process Engineer</h2>
</div>
<div class="job-location">
<p>Location: Naypyitaw</p>
</div>
<div class="job-type">
<p>Type: Full-Time</p>
</div>
<div class="job-date">
<p>Published on 07/19/2019</p>
</div>
<div class="job-industry">
<p>Engineering</p>
</div>
<ul class="job-keywords">
<li>Engineering</li>
<li>Science</li>
</ul>
</li>
<li class="job job-2">
<div class="job-title">
<h2>Chief Financial Officier</h2>
</div>
<div class="job-location">
<p>Location: Naypyitaw</p>
</div>
<div class="job-type">
<p>Type: Full-Time</p>
</div>
<div class="job-date">
<p>Published on 07/18/2019</p>
</div>
</li>
<li class="job job-3">
<div class="job-title">
<h2>Assistant CEO</h2>
</div>
<div class="job-location">
<p>Location: Naypyitaw</p>
</div>
<div class="job-type">
<p>Type: Part-Time</p>
</div>
<div class="job-date">
<p>Published on 07/18/2019</p>
</div>
</li>
<li class="job job-4">
<div class="job-title">
<h2>Front-End Developer</h2>
</div>
<div class="job-location">
<p>Location: Naypyitaw</p>
</div>
<div class="job-type">
<p>Type: Part-Time</p>
</div>
<div class="job-date">
<p>Published on 07/18/2019</p>
</div>
</li>
</ul>
<nav class="pagination-container">
<ul class="pagination">
<li><a href="javascript:void(0)">Previous</a></li>
<li><a href="javascript:void(0)">Next</a></li>
</ul>
</nav>
</div>
</div>